Final Project Goal

Harry Potter’s Network:

For our final project, we chose to analyze Harry Potter’s Network. As a new Harry Potter game is coming out on the Iphone/Android (similar to Pokemon Go), we decided to help people make their character pick easier.

https://www.cnet.com/news/harry-potter-wizards-unite-mixes-pokemon-go-with-a-mobile-mystery-but-release-date-remains-hidden/

Therefore, we chose to analyze this network to evaluate if Harry Potter, the protagonist and supposedly main character of the movies, is actually the most important character within the story line (and the best choice for the game). We will base our conclusion by exploring the following network through various network techniques and subjects:

  • Network Properties
  • Network Measures: Centrality
  • Network Measures: Transitivity
  • Network Models: Real World Networks
  • Information Diffusion
  • Community Detection
  • Network Visualization

In addition, we wanted to evaluate which other characters played important roles in the story line.

Clearing and Loading Libraries

Load the mandatory libraries to run the whole project:

#dev.off() #should be run only if R is not under default parameters

rm(list=ls()) #clear environment from past data

list_of_packages <-c("data.table", "igraph", "visNetwork", "CINNA", "centiserve", "keyplayer", "dplyr", "sna")

new_packages <- list_of_packages[!(list_of_packages %in% installed.packages()[,"Package"])]
if(length(new_packages)) install.packages(new_packages) #install libraries from the list of packages only if they haven't already been installed 

library("data.table")
library("igraph")
## Warning: package 'igraph' was built under R version 3.5.2
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union
library("CINNA")
## Warning: package 'CINNA' was built under R version 3.5.2
library("visNetwork")
## Warning: package 'visNetwork' was built under R version 3.5.2
library("centiserve")
## Warning: package 'centiserve' was built under R version 3.5.2
## Loading required package: Matrix
library("keyplayer")
## Warning: package 'keyplayer' was built under R version 3.5.2
## 
## Attaching package: 'keyplayer'
## The following object is masked from 'package:igraph':
## 
##     contract
library("dplyr")
## Warning: package 'dplyr' was built under R version 3.5.2
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:igraph':
## 
##     as_data_frame, groups, union
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library("sna")
## Warning: package 'sna' was built under R version 3.5.2
## Loading required package: statnet.common
## Warning: package 'statnet.common' was built under R version 3.5.2
## 
## Attaching package: 'statnet.common'
## The following object is masked from 'package:base':
## 
##     order
## Loading required package: network
## Warning: package 'network' was built under R version 3.5.2
## network: Classes for Relational Data
## Version 1.13.0.1 created on 2015-08-31.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
##                     Mark S. Handcock, University of California -- Los Angeles
##                     David R. Hunter, Penn State University
##                     Martina Morris, University of Washington
##                     Skye Bender-deMoll, University of Washington
##  For citation information, type citation("network").
##  Type help("network-package") to get started.
## 
## Attaching package: 'network'
## The following objects are masked from 'package:igraph':
## 
##     %c%, %s%, add.edges, add.vertices, delete.edges,
##     delete.vertices, get.edge.attribute, get.edges,
##     get.vertex.attribute, is.bipartite, is.directed,
##     list.edge.attributes, list.vertex.attributes,
##     set.edge.attribute, set.vertex.attribute
## sna: Tools for Social Network Analysis
## Version 2.4 created on 2016-07-23.
## copyright (c) 2005, Carter T. Butts, University of California-Irvine
##  For citation information, type citation("sna").
##  Type help(package="sna") to get started.
## 
## Attaching package: 'sna'
## The following objects are masked from 'package:igraph':
## 
##     betweenness, bonpow, closeness, components, degree,
##     dyad.census, evcent, hierarchy, is.connected, neighborhood,
##     triad.census
#load all libraries from the list of packages

Loading Data

In this section, the goal is loading the given datasets, building the graph and analyzing basics metrics.

Harry Potter’s Network:

There are two data frames that were loaded, the Edges and the Keys.

The Keys dataframe shows a list of 65 Characters and includes information regarding their alignment, gender, house to which they belong and the color attributed to that house. These 65 characters are regarded as the most important characters within all the Harry Potter movies.

The Edge dataframe shows 513 links between characters (links between each character name (source) with another character (target)). However, many have duplicated loops, so that when we remove those, the number of edges decreases to 330. There is no need for duplicated loops in this case because our graph is undirected and if one character knows another, then automatically, the inverse is true.

In all, the joint graph (igraph) of the edges and keys is an undirected and unweighted network.The dataframe is unweighted because the links are based on which Characters know each other.

edges <- as.data.frame(fread("https://gist.githubusercontent.com/CamilleBlainCoallier/3e5604911cad5004bfe213030291808a/raw/58bdd7a0dce34e0f5de309fe8d6c1ce536ef148b/Edge_list_HP"))
keys <- as.data.frame(fread("https://gist.githubusercontent.com/CamilleBlainCoallier/7c564144a0c8397fac1b6b67c5776616/raw/2be29fbc24fcb55022b07ce40cc4d74786821e61/Keys_nodes_HP"))

summary(edges) #list of links between characters (target to source)
##   Source                        Target                      
##  NULL:Regulus Arcturus Black   NULL:Sirius Black            
##  NULL:Regulus Arcturus Black   NULL:Bellatrix Lestrange     
##  NULL:Regulus Arcturus Black   NULL:Lord Voldemort          
##  NULL:Sirius Black             NULL:Regulus Arcturus Black  
##  NULL:Sirius Black             NULL:Albus Dumbledore        
##  NULL:Sirius Black             NULL:Hermione Granger        
##  NULL:Sirius Black             NULL:Bellatrix Lestrange     
##  NULL:Sirius Black             NULL:Remus Lupin             
##  NULL:Sirius Black             NULL:Lucius Malfoy           
##  NULL:Sirius Black             NULL:Narcissa Malfoy         
##  NULL:Sirius Black             NULL:Minerva McGonagall      
##  NULL:Sirius Black             NULL:Alastor Moody           
##  NULL:Sirius Black             NULL:Peter Pettigrew         
##  NULL:Sirius Black             NULL:Harry Potter            
##  NULL:Sirius Black             NULL:James Potter            
##  NULL:Sirius Black             NULL:Lily Potter             
##  NULL:Sirius Black             NULL:Lord Voldemort          
##  NULL:Sirius Black             NULL:Severus Snape           
##  NULL:Sirius Black             NULL:Nymphadora Tonks        
##  NULL:Sirius Black             NULL:Arthur Weasley          
##  NULL:Sirius Black             NULL:Fred Weasley            
##  NULL:Sirius Black             NULL:George Weasley          
##  NULL:Sirius Black             NULL:Ginny Weasley           
##  NULL:Sirius Black             NULL:Ron Weasley             
##  NULL:Lavender Brown           NULL:Hermione Granger        
##  NULL:Lavender Brown           NULL:Neville Longbottom      
##  NULL:Lavender Brown           NULL:Ron Weasley             
##  NULL:Cho Chang                NULL:Cedric Diggory          
##  NULL:Cho Chang                NULL:Seamus Finnigan         
##  NULL:Cho Chang                NULL:Hermione Granger        
##  NULL:Cho Chang                NULL:Neville Longbottom      
##  NULL:Cho Chang                NULL:Harry Potter            
##  NULL:Cho Chang                NULL:Lord Voldemort          
##  NULL:Cho Chang                NULL:Ron Weasley             
##  NULL:Vincent Crabbe Sr.       NULL:Regulus Arcturus Black  
##  NULL:Vincent Crabbe Sr.       NULL:Vincent Crabbe          
##  NULL:Vincent Crabbe Sr.       NULL:Bartemius Crouch Sr.    
##  NULL:Vincent Crabbe Sr.       NULL:Bellatrix Lestrange     
##  NULL:Vincent Crabbe Sr.       NULL:Lucius Malfoy           
##  NULL:Vincent Crabbe Sr.       NULL:Peter Pettigrew         
##  NULL:Vincent Crabbe Sr.       NULL:Lord Voldemort          
##  NULL:Vincent Crabbe Sr.       NULL:Severus Snape           
##  NULL:Vincent Crabbe           NULL:Vincent Crabbe Sr.      
##  NULL:Vincent Crabbe           NULL:Dolores Janes Umbridge  
##  NULL:Vincent Crabbe           NULL:Gregory Goyle           
##  NULL:Vincent Crabbe           NULL:Hermione Granger        
##  NULL:Vincent Crabbe           NULL:Draco Malfoy            
##  NULL:Vincent Crabbe           NULL:Harry Potter            
##  NULL:Vincent Crabbe           NULL:Ron Weasley             
##  NULL:Bartemius Crouch Sr.     NULL:Vincent Crabbe Sr.      
##  NULL:Bartemius Crouch Sr.     NULL:Bartemius Crouch Jr.    
##  NULL:Bartemius Crouch Sr.     NULL:Igor Karkaroff          
##  NULL:Bartemius Crouch Sr.     NULL:Percy Weasley           
##  NULL:Bartemius Crouch Jr.     NULL:Bartemius Crouch Sr.    
##  NULL:Bartemius Crouch Jr.     NULL:Hermione Granger        
##  NULL:Bartemius Crouch Jr.     NULL:Neville Longbottom      
##  NULL:Bartemius Crouch Jr.     NULL:Minerva McGonagall      
##  NULL:Bartemius Crouch Jr.     NULL:Alastor Moody           
##  NULL:Bartemius Crouch Jr.     NULL:Harry Potter            
##  NULL:Bartemius Crouch Jr.     NULL:Lord Voldemort          
##  NULL:Bartemius Crouch Jr.     NULL:Severus Snape           
##  NULL:Bartemius Crouch Jr.     NULL:Peter Pettigrew         
##  NULL:Fleur Delacour           NULL:Hermione Granger        
##  NULL:Fleur Delacour           NULL:Bellatrix Lestrange     
##  NULL:Fleur Delacour           NULL:Neville Longbottom      
##  NULL:Fleur Delacour           NULL:Alastor Moody           
##  NULL:Fleur Delacour           NULL:Harry Potter            
##  NULL:Fleur Delacour           NULL:Bill Weasley            
##  NULL:Fleur Delacour           NULL:Ginny Weasley           
##  NULL:Fleur Delacour           NULL:Molly Weasley           
##  NULL:Fleur Delacour           NULL:Ron Weasley             
##  NULL:Cedric Diggory           NULL:Cho Chang               
##  NULL:Cedric Diggory           NULL:Harry Potter            
##  NULL:Cedric Diggory           NULL:Lord Voldemort          
##  NULL:Aberforth Dumbledore     NULL:Albus Dumbledore        
##  NULL:Aberforth Dumbledore     NULL:Hermione Granger        
##  NULL:Aberforth Dumbledore     NULL:Harry Potter            
##  NULL:Aberforth Dumbledore     NULL:Ron Weasley             
##  NULL:Aberforth Dumbledore     NULL:Dobby                   
##  NULL:Albus Dumbledore         NULL:Sirius Black            
##  NULL:Albus Dumbledore         NULL:Aberforth Dumbledore    
##  NULL:Albus Dumbledore         NULL:Petunia Dursley         
##  NULL:Albus Dumbledore         NULL:Vernon Dursley          
##  NULL:Albus Dumbledore         NULL:Hermione Granger        
##  NULL:Albus Dumbledore         NULL:Rubeus Hagrid           
##  NULL:Albus Dumbledore         NULL:Bellatrix Lestrange     
##  NULL:Albus Dumbledore         NULL:Remus Lupin             
##  NULL:Albus Dumbledore         NULL:Minerva McGonagall      
##  NULL:Albus Dumbledore         NULL:Minerva McGonagall      
##  NULL:Albus Dumbledore         NULL:Alastor Moody           
##  NULL:Albus Dumbledore         NULL:Peter Pettigrew         
##  NULL:Albus Dumbledore         NULL:Harry Potter            
##  NULL:Albus Dumbledore         NULL:James Potter            
##  NULL:Albus Dumbledore         NULL:Lily Potter             
##  NULL:Albus Dumbledore         NULL:Quirinus Quirrell       
##  NULL:Albus Dumbledore         NULL:Lord Voldemort          
##  NULL:Albus Dumbledore         NULL:Rita Skeeter            
##  NULL:Albus Dumbledore         NULL:Severus Snape           
##  NULL:Albus Dumbledore         NULL:Dolores Janes Umbridge  
##  NULL:Albus Dumbledore         NULL:Dolores Janes Umbridge  
##  NULL:Albus Dumbledore         NULL:Arthur Weasley          
##  NULL:Albus Dumbledore         NULL:Bill Weasley            
##  NULL:Albus Dumbledore         NULL:Charlie Weasley         
##  NULL:Albus Dumbledore         NULL:Fred Weasley            
##  NULL:Albus Dumbledore         NULL:George Weasley          
##  NULL:Albus Dumbledore         NULL:Ginny Weasley           
##  NULL:Albus Dumbledore         NULL:Molly Weasley           
##  NULL:Albus Dumbledore         NULL:Percy Weasley           
##  NULL:Albus Dumbledore         NULL:Ron Weasley             
##  NULL:Dudley Dursley           NULL:Dudley Dursley          
##  NULL:Dudley Dursley           NULL:Vernon Dursley          
##  NULL:Dudley Dursley           NULL:Harry Potter            
##  NULL:Dudley Dursley           NULL:Rubeus Hagrid           
##  NULL:Petunia Dursley          NULL:Albus Dumbledore        
##  NULL:Petunia Dursley          NULL:Dudley Dursley          
##  NULL:Petunia Dursley          NULL:Petunia Dursley         
##  NULL:Petunia Dursley          NULL:Harry Potter            
##  NULL:Petunia Dursley          NULL:Lily Potter             
##  NULL:Vernon Dursley           NULL:Albus Dumbledore        
##  NULL:Vernon Dursley           NULL:Dudley Dursley          
##  NULL:Vernon Dursley           NULL:Petunia Dursley         
##  NULL:Vernon Dursley           NULL:Harry Potter            
##  NULL:Argus Filch              NULL:Sirius Black            
##  NULL:Argus Filch              NULL:Albus Dumbledore        
##  NULL:Argus Filch              NULL:Rubeus Hagrid           
##  NULL:Argus Filch              NULL:Minerva McGonagall      
##  NULL:Argus Filch              NULL:Peter Pettigrew         
##  NULL:Argus Filch              NULL:Harry Potter            
##  NULL:Argus Filch              NULL:James Potter            
##  NULL:Argus Filch              NULL:Severus Snape           
##  NULL:Argus Filch              NULL:Dolores Janes Umbridge  
##  NULL:Argus Filch              NULL:Fred Weasley            
##  NULL:Argus Filch              NULL:George Weasley          
##  NULL:Seamus Finnigan          NULL:Lavender Brown          
##  NULL:Seamus Finnigan          NULL:Cho Chang               
##  NULL:Seamus Finnigan          NULL:Hermione Granger        
##  NULL:Seamus Finnigan          NULL:Neville Longbottom      
##  NULL:Seamus Finnigan          NULL:Luna Lovegood           
##  NULL:Seamus Finnigan          NULL:Harry Potter            
##  NULL:Seamus Finnigan          NULL:Ginny Weasley           
##  NULL:Seamus Finnigan          NULL:Ron Weasley             
##  NULL:Nicolas Flamel           NULL:Albus Dumbledore        
##  NULL:Cornelius Fudge          NULL:Albus Dumbledore        
##  NULL:Cornelius Fudge          NULL:Lucius Malfoy           
##  NULL:Cornelius Fudge          NULL:Harry Potter            
##  NULL:Cornelius Fudge          NULL:Dolores Janes Umbridge  
##  NULL:Cornelius Fudge          NULL:Arthur Weasley          
##  NULL:Cornelius Fudge          NULL:Percy Weasley           
##  NULL:Goyle Sr.                NULL:Vincent Crabbe Sr.      
##  NULL:Goyle Sr.                NULL:Gregory Goyle           
##  NULL:Goyle Sr.                NULL:Lord Voldemort          
##  NULL:Gregory Goyle            NULL:Goyle Sr.               
##  NULL:Gregory Goyle            NULL:Vincent Crabbe          
##  NULL:Gregory Goyle            NULL:Draco Malfoy            
##  NULL:Gregory Goyle            NULL:Harry Potter            
##  NULL:Gregory Goyle            NULL:Lord Voldemort          
##  NULL:Hermione Granger         NULL:Harry Potter            
##  NULL:Hermione Granger         NULL:Ron Weasley             
##  NULL:Hermione Granger         NULL:George Weasley          
##  NULL:Hermione Granger         NULL:Molly Weasley           
##  NULL:Hermione Granger         NULL:Severus Snape           
##  NULL:Hermione Granger         NULL:Luna Lovegood           
##  NULL:Hermione Granger         NULL:Neville Longbottom      
##  NULL:Hermione Granger         NULL:Lord Voldemort          
##  NULL:Hermione Granger         NULL:Peter Pettigrew         
##  NULL:Hermione Granger         NULL:Draco Malfoy            
##  NULL:Hermione Granger         NULL:Argus Filch             
##  NULL:Hermione Granger         NULL:Gregory Goyle           
##  NULL:Rubeus Hagrid            NULL:Lord Voldemort          
##  NULL:Rubeus Hagrid            NULL:Fluffy                  
##  NULL:Rubeus Hagrid            NULL:Aragog                  
##  NULL:Rubeus Hagrid            NULL:Grawp                   
##  NULL:Rubeus Hagrid            NULL:Ron Weasley             
##  NULL:Rubeus Hagrid            NULL:Hermione Granger        
##  NULL:Rubeus Hagrid            NULL:Severus Snape           
##  NULL:Rubeus Hagrid            NULL:Harry Potter            
##  NULL:Rubeus Hagrid            NULL:Neville Longbottom      
##  NULL:Rubeus Hagrid            NULL:Olympe Maxime           
##  NULL:Rubeus Hagrid            NULL:Minerva McGonagall      
##  NULL:Rubeus Hagrid            NULL:Albus Dumbledore        
##  NULL:Igor Karkaroff           NULL:Lord Voldemort          
##  NULL:Igor Karkaroff           NULL:Viktor Krum             
##  NULL:Viktor Krum              NULL:Igor Karkaroff          
##  NULL:Viktor Krum              NULL:Harry Potter            
##  NULL:Viktor Krum              NULL:Fleur Delacour          
##  NULL:Viktor Krum              NULL:Cedric Diggory          
##  NULL:Viktor Krum              NULL:Hermione Granger        
##  NULL:Bellatrix Lestrange      NULL:Lord Voldemort          
##  NULL:Bellatrix Lestrange      NULL:Lucius Malfoy           
##  NULL:Bellatrix Lestrange      NULL:Narcissa Malfoy         
##  NULL:Bellatrix Lestrange      NULL:Sirius Black            
##  NULL:Bellatrix Lestrange      NULL:Harry Potter            
##  NULL:Bellatrix Lestrange      NULL:Nymphadora Tonks        
##  NULL:Bellatrix Lestrange      NULL:Molly Weasley           
##  NULL:Bellatrix Lestrange      NULL:Dobby                   
##  NULL:Alice Longbottom         NULL:Frank Longbottom        
##  NULL:Alice Longbottom         NULL:Frank Longbottom        
##  NULL:Alice Longbottom         NULL:Neville Longbottom      
##  NULL:Frank Longbottom         NULL:Alice Longbottom        
##  NULL:Frank Longbottom         NULL:Lord Voldemort          
##  NULL:Frank Longbottom         NULL:Neville Longbottom      
##  NULL:Neville Longbottom       NULL:Harry Potter            
##  NULL:Neville Longbottom       NULL:Lord Voldemort          
##  NULL:Neville Longbottom       NULL:Hermione Granger        
##  NULL:Neville Longbottom       NULL:Ron Weasley             
##  NULL:Neville Longbottom       NULL:Luna Lovegood           
##  NULL:Neville Longbottom       NULL:Draco Malfoy            
##  NULL:Luna Lovegood            NULL:Neville Longbottom      
##  NULL:Luna Lovegood            NULL:Harry Potter            
##  NULL:Luna Lovegood            NULL:Hermione Granger        
##  NULL:Luna Lovegood            NULL:Ron Weasley             
##  NULL:Xenophilius Lovegood     NULL:Luna Lovegood           
##  NULL:Remus Lupin              NULL:Peter Pettigrew         
##  NULL:Remus Lupin              NULL:Lord Voldemort          
##  NULL:Remus Lupin              NULL:James Potter            
##  NULL:Remus Lupin              NULL:Sirius Black            
##  NULL:Remus Lupin              NULL:Nymphadora Tonks        
##  NULL:Remus Lupin              NULL:Harry Potter            
##  NULL:Remus Lupin              NULL:Minerva McGonagall      
##  NULL:Draco Malfoy             NULL:Vincent Crabbe          
##  NULL:Draco Malfoy             NULL:Gregory Goyle           
##  NULL:Draco Malfoy             NULL:Lucius Malfoy           
##  NULL:Draco Malfoy             NULL:Narcissa Malfoy         
##  NULL:Draco Malfoy             NULL:Harry Potter            
##  NULL:Draco Malfoy             NULL:Hermione Granger        
##  NULL:Draco Malfoy             NULL:Ron Weasley             
##  NULL:Lucius Malfoy            NULL:Draco Malfoy            
##  NULL:Lucius Malfoy            NULL:Narcissa Malfoy         
##  NULL:Lucius Malfoy            NULL:Lord Voldemort          
##  NULL:Lucius Malfoy            NULL:Harry Potter            
##  NULL:Lucius Malfoy            NULL:Dobby                   
##  NULL:Narcissa Malfoy          NULL:Lucius Malfoy           
##  NULL:Narcissa Malfoy          NULL:Lord Voldemort          
##  NULL:Narcissa Malfoy          NULL:Bellatrix Lestrange     
##  NULL:Olympe Maxime            NULL:Rubeus Hagrid           
##  NULL:Olympe Maxime            NULL:Fleur Delacour          
##  NULL:Olympe Maxime            NULL:Albus Dumbledore        
##  NULL:Olympe Maxime            NULL:Igor Karkaroff          
##  NULL:Minerva McGonagall       NULL:Argus Filch             
##  NULL:Minerva McGonagall       NULL:Rubeus Hagrid           
##  NULL:Minerva McGonagall       NULL:Dolores Janes Umbridge  
##  NULL:Minerva McGonagall       NULL:Lord Voldemort          
##  NULL:Minerva McGonagall       NULL:Albus Dumbledore        
##  NULL:Minerva McGonagall       NULL:Harry Potter            
##  NULL:Harry Potter             NULL:Minerva McGonagall      
##  NULL:Minerva McGonagall       NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Minerva McGonagall      
##  NULL:Minerva McGonagall       NULL:Ron Weasley             
##  NULL:Ron Weasley              NULL:Minerva McGonagall      
##  NULL:Minerva McGonagall       NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:Minerva McGonagall      
##  NULL:Minerva McGonagall       NULL:Albus Dumbledore        
##  NULL:Albus Dumbledore         NULL:Minerva McGonagall      
##  NULL:Alastor Moody            NULL:Harry Potter            
##  NULL:Alastor Moody            NULL:Arthur Weasley          
##  NULL:Alastor Moody            NULL:Molly Weasley           
##  NULL:Harry Potter             NULL:Alastor Moody           
##  NULL:Harry Potter             NULL:Lord Voldemort          
##  NULL:Alastor Moody            NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Alastor Moody           
##  NULL:Alastor Moody            NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Alastor Moody           
##  NULL:Alastor Moody            NULL:Bartemius Crouch Jr.    
##  NULL:Bartemius Crouch Jr.     NULL:Alastor Moody           
##  NULL:Alastor Moody            NULL:Albus Dumbledore        
##  NULL:Albus Dumbledore         NULL:Alastor Moody           
##  NULL:Alastor Moody            NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:Alastor Moody           
##  NULL:Peter Pettigrew          NULL:Sirius Black            
##  NULL:Sirius Black             NULL:Peter Pettigrew         
##  NULL:Peter Pettigrew          NULL:James Potter            
##  NULL:James Potter             NULL:Peter Pettigrew         
##  NULL:Peter Pettigrew          NULL:Lily Potter             
##  NULL:Lily Potter              NULL:Peter Pettigrew         
##  NULL:Lily Potter              NULL:Harry Potter            
##  NULL:Peter Pettigrew          NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:Peter Pettigrew         
##  NULL:Peter Pettigrew          NULL:Harry Potter            
##  NULL:Harry Potter             NULL:Peter Pettigrew         
##  NULL:James Potter             NULL:Harry Potter            
##  NULL:Harry Potter             NULL:James Potter            
##  NULL:James Potter             NULL:Remus Lupin             
##  NULL:Remus Lupin              NULL:James Potter            
##  NULL:James Potter             NULL:Sirius Black            
##  NULL:Sirius Black             NULL:James Potter            
##  NULL:James Potter             NULL:Peter Pettigrew         
##  NULL:Peter Pettigrew          NULL:James Potter            
##  NULL:James Potter             NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:James Potter            
##  NULL:James Potter             NULL:Lily Potter             
##  NULL:Lily Potter              NULL:James Potter            
##  NULL:Lily Potter              NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:Lily Potter             
##  NULL:Lily Potter              NULL:Severus Snape           
##  NULL:Severus Snape            NULL:Lily Potter             
##  NULL:Quirinus Quirrell        NULL:Harry Potter            
##  NULL:Harry Potter             NULL:Quirinus Quirrell       
##  NULL:Quirinus Quirrell        NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Quirinus Quirrell       
##  NULL:Quirinus Quirrell        NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Quirinus Quirrell       
##  NULL:Quirinus Quirrell        NULL:Albus Dumbledore        
##  NULL:Albus Dumbledore         NULL:Quirinus Quirrell       
##  NULL:Quirinus Quirrell        NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:Quirinus Quirrell       
##  NULL:Tom Riddle Sr.           NULL:Lord Voldemort          
##  NULL:Tom Riddle Sr.           NULL:Tom Riddle Sr.          
##  NULL:Tom Riddle Sr.           NULL:Mary Riddle             
##  NULL:Mary Riddle              NULL:Tom Riddle Sr.          
##  NULL:Mary Riddle              NULL:Lord Voldemort          
##  NULL:Tom Riddle Sr.           NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:Tom Riddle Sr.          
##  NULL:Rita Skeeter             NULL:Harry Potter            
##  NULL:Harry Potter             NULL:Rita Skeeter            
##  NULL:Rita Skeeter             NULL:Albus Dumbledore        
##  NULL:Albus Dumbledore         NULL:Rita Skeeter            
##  NULL:Severus Snape            NULL:Harry Potter            
##  NULL:Harry Potter             NULL:Severus Snape           
##  NULL:Severus Snape            NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Severus Snape           
##  NULL:Severus Snape            NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Severus Snape           
##  NULL:Quirinus Quirrell        NULL:Albus Dumbledore        
##  NULL:Albus Dumbledore         NULL:Quirinus Quirrell       
##  NULL:Severus Snape            NULL:Lily Potter             
##  NULL:Lily Potter              NULL:Severus Snape           
##  NULL:Severus Snape            NULL:Lord Voldemort          
##  NULL:Lord Voldemort           NULL:Severus Snape           
##  NULL:Nymphadora Tonks         NULL:Remus Lupin             
##  NULL:Nymphadora Tonks         NULL:Lord Voldemort          
##  NULL:Remus Lupin              NULL:Nymphadora Tonks        
##  NULL:Dolores Janes Umbridge   NULL:Harry Potter            
##  NULL:Harry Potter             NULL:Dolores Janes Umbridge  
##  NULL:Dolores Janes Umbridge   NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Dolores Janes Umbridge  
##  NULL:Dolores Janes Umbridge   NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Dolores Janes Umbridge  
##  NULL:Dolores Janes Umbridge   NULL:Albus Dumbledore        
##  NULL:Albus Dumbledore         NULL:Dolores Janes Umbridge  
##  NULL:Dolores Janes Umbridge   NULL:Cornelius Fudge         
##  NULL:Cornelius Fudge          NULL:Dolores Janes Umbridge  
##  NULL:Arthur Weasley           NULL:Hermione Granger        
##  NULL:Arthur Weasley           NULL:Sirius Black            
##  NULL:Arthur Weasley           NULL:Albus Dumbledore        
##  NULL:Arthur Weasley           NULL:Lucius Malfoy           
##  NULL:Arthur Weasley           NULL:Harry Potter            
##  NULL:Hermione Granger         NULL:Arthur Weasley          
##  NULL:Arthur Weasley           NULL:Bill Weasley            
##  NULL:Bill Weasley             NULL:Arthur Weasley          
##  NULL:Arthur Weasley           NULL:Charlie Weasley         
##  NULL:Charlie Weasley          NULL:Arthur Weasley          
##  NULL:Arthur Weasley           NULL:Fred Weasley            
##  NULL:Fred Weasley             NULL:Arthur Weasley          
##  NULL:Arthur Weasley           NULL:George Weasley          
##  NULL:George Weasley           NULL:Arthur Weasley          
##  NULL:Arthur Weasley           NULL:George Weasley          
##  NULL:George Weasley           NULL:Arthur Weasley          
##  NULL:Arthur Weasley           NULL:Ginny Weasley           
##  NULL:Ginny Weasley            NULL:Arthur Weasley          
##  NULL:Arthur Weasley           NULL:Percy Weasley           
##  NULL:Percy Weasley            NULL:Arthur Weasley          
##  NULL:Bill Weasley             NULL:Harry Potter            
##  NULL:Bill Weasley             NULL:Lord Voldemort          
##  NULL:Bill Weasley             NULL:Hermione Granger        
##  NULL:Hermione Granger         NULL:Bill Weasley            
##  NULL:Arthur Weasley           NULL:Bill Weasley            
##  NULL:Bill Weasley             NULL:Arthur Weasley          
##  NULL:Bill Weasley             NULL:Charlie Weasley         
##  NULL:Charlie Weasley          NULL:Bill Weasley            
##  NULL:Bill Weasley             NULL:Fred Weasley            
##  NULL:Fred Weasley             NULL:Bill Weasley            
##  NULL:Bill Weasley             NULL:George Weasley          
##  NULL:George Weasley           NULL:Bill Weasley            
##  NULL:Bill Weasley             NULL:George Weasley          
##  NULL:George Weasley           NULL:Bill Weasley            
##  NULL:Bill Weasley             NULL:Ginny Weasley           
##  NULL:Ginny Weasley            NULL:Bill Weasley            
##  NULL:Bill Weasley             NULL:Percy Weasley           
##  NULL:Percy Weasley            NULL:Bill Weasley            
##  NULL:Charlie Weasley          NULL:Hermione Granger        
##  NULL:Charlie Weasley          NULL:Harry Potter            
##  NULL:Hermione Granger         NULL:Charlie Weasley         
##  NULL:Arthur Weasley           NULL:Charlie Weasley         
##  NULL:Charlie Weasley          NULL:Arthur Weasley          
##  NULL:Charlie Weasley          NULL:Fred Weasley            
##  NULL:Fred Weasley             NULL:Charlie Weasley         
##  NULL:Charlie Weasley          NULL:George Weasley          
##  NULL:George Weasley           NULL:Charlie Weasley         
##  NULL:Charlie Weasley          NULL:George Weasley          
##  NULL:Charlie Weasley          NULL:Lord Voldemort          
##  NULL:George Weasley           NULL:Charlie Weasley         
##  NULL:Charlie Weasley          NULL:Ginny Weasley           
##  NULL:Ginny Weasley            NULL:Charlie Weasley         
##  NULL:Charlie Weasley          NULL:Percy Weasley           
##  NULL:Percy Weasley            NULL:Charlie Weasley         
##  NULL:Fred Weasley             NULL:Hermione Granger        
##  NULL:Fred Weasley             NULL:Remus Lupin             
##  NULL:Fred Weasley             NULL:Peter Pettigrew         
##  NULL:Fred Weasley             NULL:Harry Potter            
##  NULL:Fred Weasley             NULL:Lord Voldemort          
##  NULL:Fred Weasley             NULL:Severus Snape           
##  NULL:Fred Weasley             NULL:Arthur Weasley          
##  NULL:Fred Weasley             NULL:Bill Weasley            
##  NULL:Fred Weasley             NULL:Charlie Weasley         
##  NULL:Fred Weasley             NULL:George Weasley          
##  NULL:Fred Weasley             NULL:Ginny Weasley           
##  NULL:Fred Weasley             NULL:Molly Weasley           
##  NULL:Fred Weasley             NULL:Percy Weasley           
##  NULL:Fred Weasley             NULL:Ron Weasley             
##  NULL:George Weasley           NULL:Hermione Granger        
##  NULL:George Weasley           NULL:Remus Lupin             
##  NULL:George Weasley           NULL:Peter Pettigrew         
##  NULL:George Weasley           NULL:Harry Potter            
##  NULL:George Weasley           NULL:Lord Voldemort          
##  NULL:George Weasley           NULL:Severus Snape           
##  NULL:George Weasley           NULL:Arthur Weasley          
##  NULL:George Weasley           NULL:Bill Weasley            
##  NULL:George Weasley           NULL:Charlie Weasley         
##  NULL:George Weasley           NULL:Fred Weasley            
##  NULL:George Weasley           NULL:Ginny Weasley           
##  NULL:George Weasley           NULL:Molly Weasley           
##  NULL:George Weasley           NULL:Percy Weasley           
##  NULL:George Weasley           NULL:Ron Weasley             
##  NULL:Ginny Weasley            NULL:Hermione Granger        
##  NULL:Ginny Weasley            NULL:Remus Lupin             
##  NULL:Ginny Weasley            NULL:Peter Pettigrew         
##  NULL:Ginny Weasley            NULL:Harry Potter            
##  NULL:Ginny Weasley            NULL:Lord Voldemort          
##  NULL:Ginny Weasley            NULL:Severus Snape           
##  NULL:Ginny Weasley            NULL:Arthur Weasley          
##  NULL:Ginny Weasley            NULL:Bill Weasley            
##  NULL:Ginny Weasley            NULL:Charlie Weasley         
##  NULL:Ginny Weasley            NULL:George Weasley          
##  NULL:Ginny Weasley            NULL:Fred Weasley            
##  NULL:Ginny Weasley            NULL:Molly Weasley           
##  NULL:Ginny Weasley            NULL:Percy Weasley           
##  NULL:Ginny Weasley            NULL:Percy Weasley           
##  NULL:Ginny Weasley            NULL:Ron Weasley             
##  NULL:Molly Weasley            NULL:Sirius Black            
##  NULL:Molly Weasley            NULL:Albus Dumbledore        
##  NULL:Molly Weasley            NULL:Hermione Granger        
##  NULL:Molly Weasley            NULL:Lucius Malfoy           
##  NULL:Molly Weasley            NULL:Harry Potter            
##  NULL:Molly Weasley            NULL:Lord Voldemort          
##  NULL:Molly Weasley            NULL:Arthur Weasley          
##  NULL:Molly Weasley            NULL:Bill Weasley            
##  NULL:Molly Weasley            NULL:Charlie Weasley         
##  NULL:Molly Weasley            NULL:Fred Weasley            
##  NULL:Molly Weasley            NULL:George Weasley          
##  NULL:Molly Weasley            NULL:Ginny Weasley           
##  NULL:Molly Weasley            NULL:Percy Weasley           
##  NULL:Molly Weasley            NULL:Ron Weasley             
##  NULL:Percy Weasley            NULL:Arthur Weasley          
##  NULL:Percy Weasley            NULL:Bill Weasley            
##  NULL:Percy Weasley            NULL:Charlie Weasley         
##  NULL:Percy Weasley            NULL:Fred Weasley            
##  NULL:Percy Weasley            NULL:George Weasley          
##  NULL:Percy Weasley            NULL:Ginny Weasley           
##  NULL:Percy Weasley            NULL:Molly Weasley           
##  NULL:Percy Weasley            NULL:Ron Weasley             
##  NULL:Ron Weasley              NULL:Sirius Black            
##  NULL:Ron Weasley              NULL:Fleur Delacour          
##  NULL:Ron Weasley              NULL:Albus Dumbledore        
##  NULL:Ron Weasley              NULL:Argus Filch             
##  NULL:Ron Weasley              NULL:Seamus Finnigan         
##  NULL:Ron Weasley              NULL:Gregory Goyle           
##  NULL:Ron Weasley              NULL:Hermione Granger        
##  NULL:Ron Weasley              NULL:Rubeus Hagrid           
##  NULL:Ron Weasley              NULL:Bellatrix Lestrange     
##  NULL:Ron Weasley              NULL:Neville Longbottom      
##  NULL:Ron Weasley              NULL:Luna Lovegood           
##  NULL:Ron Weasley              NULL:Remus Lupin             
##  NULL:Ron Weasley              NULL:Draco Malfoy            
##  NULL:Ron Weasley              NULL:Lucius Malfoy           
##  NULL:Ron Weasley              NULL:Minerva McGonagall      
##  NULL:Ron Weasley              NULL:Alastor Moody           
##  NULL:Ron Weasley              NULL:Peter Pettigrew         
##  NULL:Ron Weasley              NULL:Harry Potter            
##  NULL:Ron Weasley              NULL:Lord Voldemort          
##  NULL:Ron Weasley              NULL:Severus Snape           
##  NULL:Ron Weasley              NULL:Dolores Janes Umbridge  
##  NULL:Ron Weasley              NULL:Arthur Weasley          
##  NULL:Ron Weasley              NULL:Bill Weasley            
##  NULL:Ron Weasley              NULL:Charlie Weasley         
##  NULL:Ron Weasley              NULL:Fred Weasley            
##  NULL:Ron Weasley              NULL:George Weasley          
##  NULL:Ron Weasley              NULL:Ginny Weasley           
##  NULL:Ron Weasley              NULL:Molly Weasley           
##  NULL:Ron Weasley              NULL:Percy Weasley           
##  NULL:Ron Weasley              NULL:Dobby                   
##  NULL:Ron Weasley              NULL:Fluffy                  
##  NULL:Ron Weasley              NULL:Aragog                  
##  NULL:Ron Weasley              NULL:Grawp                   
##  NULL:Dobby                    NULL:Hermione Granger        
##  NULL:Dobby                    NULL:Bellatrix Lestrange     
##  NULL:Dobby                    NULL:Draco Malfoy            
##  NULL:Dobby                    NULL:Lucius Malfoy           
##  NULL:Dobby                    NULL:Harry Potter            
##  NULL:Dobby                    NULL:Ron Weasley             
##  NULL:Fluffy                   NULL:Hermione Granger        
##  NULL:Fluffy                   NULL:Rubeus Hagrid           
##  NULL:Fluffy                   NULL:Harry Potter            
##  NULL:Fluffy                   NULL:Ron Weasley             
##  NULL:Hedwig                   NULL:Harry Potter            
##  NULL:Moaning Myrtle           NULL:Harry Potter            
##  NULL:Aragog                   NULL:Hermione Granger        
##  NULL:Aragog                   NULL:Rubeus Hagrid           
##  NULL:Aragog                   NULL:Harry Potter            
##  NULL:Aragog                   NULL:Ron Weasley             
##  NULL:Grawp                    NULL:Hermione Granger        
##  NULL:Grawp                    NULL:Rubeus Hagrid           
##  NULL:Grawp                    NULL:Harry Potter            
##  NULL:Aragog                   NULL:Ron Weasley
g1<- graph_from_data_frame(d=edges, vertices=keys, directed=F)
g1 #originally, we can see that there are 65 nodes and 513 edges from calling the graph
## IGRAPH 861035f UN-- 65 513 -- 
## + attr: name (v/c), Alignment (v/c), Gender_Male (v/n), House
## | (v/c), Color (v/c)
## + edges from 861035f (vertex names):
##  [1] Regulus Arcturus Black--Sirius Black       
##  [2] Regulus Arcturus Black--Bellatrix Lestrange
##  [3] Regulus Arcturus Black--Lord Voldemort     
##  [4] Regulus Arcturus Black--Sirius Black       
##  [5] Sirius Black          --Albus Dumbledore   
##  [6] Sirius Black          --Hermione Granger   
##  [7] Sirius Black          --Bellatrix Lestrange
## + ... omitted several edges
g11<-igraph::simplify(g1,edge.attr.comb = "min") #removing duplicates and self-loops
g11 #after simplifying, we obtain a graph with 65 nodes but only 330 edges
## IGRAPH 861146a UN-- 65 330 -- 
## + attr: name (v/c), Alignment (v/c), Gender_Male (v/n), House
## | (v/c), Color (v/c)
## + edges from 861146a (vertex names):
##  [1] Regulus Arcturus Black--Sirius Black       
##  [2] Regulus Arcturus Black--Vincent Crabbe Sr. 
##  [3] Regulus Arcturus Black--Bellatrix Lestrange
##  [4] Regulus Arcturus Black--Lord Voldemort     
##  [5] Sirius Black          --Albus Dumbledore   
##  [6] Sirius Black          --Argus Filch        
##  [7] Sirius Black          --Hermione Granger   
## + ... omitted several edges
V(g11) #number of nodes in the network which is equal to 65 - to confirm with g11 analysis
## + 65/65 vertices, named, from 861146a:
##  [1] Regulus Arcturus Black Sirius Black           Lavender Brown        
##  [4] Cho Chang              Vincent Crabbe Sr.     Vincent Crabbe        
##  [7] Bartemius Crouch Sr.   Bartemius Crouch Jr.   Fleur Delacour        
## [10] Cedric Diggory         Aberforth Dumbledore   Albus Dumbledore      
## [13] Dudley Dursley         Petunia Dursley        Vernon Dursley        
## [16] Argus Filch            Seamus Finnigan        Nicolas Flamel        
## [19] Cornelius Fudge        Goyle Sr.              Gregory Goyle         
## [22] Hermione Granger       Rubeus Hagrid          Igor Karkaroff        
## [25] Viktor Krum            Bellatrix Lestrange    Alice Longbottom      
## [28] Frank Longbottom       Neville Longbottom     Luna Lovegood         
## + ... omitted several vertices
E(g11) #number of edges in the network which is equal to 330 - ton confirm with g11 analysis
## + 330/330 edges from 861146a (vertex names):
##  [1] Regulus Arcturus Black--Sirius Black       
##  [2] Regulus Arcturus Black--Vincent Crabbe Sr. 
##  [3] Regulus Arcturus Black--Bellatrix Lestrange
##  [4] Regulus Arcturus Black--Lord Voldemort     
##  [5] Sirius Black          --Albus Dumbledore   
##  [6] Sirius Black          --Argus Filch        
##  [7] Sirius Black          --Hermione Granger   
##  [8] Sirius Black          --Bellatrix Lestrange
##  [9] Sirius Black          --Remus Lupin        
## [10] Sirius Black          --Lucius Malfoy      
## + ... omitted several edges
vertex_attr(g11) #describes every column in the graph and the content within that column (all possible values)
## $name
##  [1] "Regulus Arcturus Black" "Sirius Black"          
##  [3] "Lavender Brown"         "Cho Chang"             
##  [5] "Vincent Crabbe Sr."     "Vincent Crabbe"        
##  [7] "Bartemius Crouch Sr."   "Bartemius Crouch Jr."  
##  [9] "Fleur Delacour"         "Cedric Diggory"        
## [11] "Aberforth Dumbledore"   "Albus Dumbledore"      
## [13] "Dudley Dursley"         "Petunia Dursley"       
## [15] "Vernon Dursley"         "Argus Filch"           
## [17] "Seamus Finnigan"        "Nicolas Flamel"        
## [19] "Cornelius Fudge"        "Goyle Sr."             
## [21] "Gregory Goyle"          "Hermione Granger"      
## [23] "Rubeus Hagrid"          "Igor Karkaroff"        
## [25] "Viktor Krum"            "Bellatrix Lestrange"   
## [27] "Alice Longbottom"       "Frank Longbottom"      
## [29] "Neville Longbottom"     "Luna Lovegood"         
## [31] "Xenophilius Lovegood"   "Remus Lupin"           
## [33] "Draco Malfoy"           "Lucius Malfoy"         
## [35] "Narcissa Malfoy"        "Olympe Maxime"         
## [37] "Minerva McGonagall"     "Alastor Moody"         
## [39] "Peter Pettigrew"        "Harry Potter"          
## [41] "James Potter"           "Lily Potter"           
## [43] "Quirinus Quirrell"      "Tom Riddle Sr."        
## [45] "Mary Riddle"            "Lord Voldemort"        
## [47] "Rita Skeeter"           "Severus Snape"         
## [49] "Nymphadora Tonks"       "Dolores Janes Umbridge"
## [51] "Arthur Weasley"         "Bill Weasley"          
## [53] "Charlie Weasley"        "Fred Weasley"          
## [55] "George Weasley"         "Ginny Weasley"         
## [57] "Molly Weasley"          "Percy Weasley"         
## [59] "Ron Weasley"            "Dobby"                 
## [61] "Fluffy"                 "Hedwig"                
## [63] "Moaning Myrtle"         "Aragog"                
## [65] "Grawp"                 
## 
## $Alignment
##  [1] "Good"    "Good"    "Good"    "Good"    "Evil"    "Evil"    "Good"   
##  [8] "Evil"    "Good"    "Good"    "Good"    "Good"    "Neutral" "Neutral"
## [15] "Neutral" "Neutral" "Good"    "Good"    "Neutral" "Evil"    "Evil"   
## [22] "Good"    "Good"    "Neutral" "Good"    "Evil"    "Good"    "Good"   
## [29] "Good"    "Good"    "Good"    "Good"    "Evil"    "Evil"    "Evil"   
## [36] "Good"    "Good"    "Good"    "Evil"    "Good"    "Good"    "Good"   
## [43] "Evil"    "Evil"    "Good"    "Evil"    "Good"    "Good"    "Good"   
## [50] "Evil"    "Good"    "Good"    "Good"    "Good"    "Good"    "Good"   
## [57] "Good"    "Good"    "Good"    "Good"    "Good"    "Good"    "Good"   
## [64] "Neutral" "Good"   
## 
## $Gender_Male
##  [1] 1 1 0 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 1 0
## [36] 0 0 1 1 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 1 1
## 
## $House
##  [1] "Slytherin"   "Gryffindor"  "Gryffindor"  "Ravenclaw"   "Slytherin"  
##  [6] "Slytherin"   NA            NA            "Beauxbatons" "Hufflepuff" 
## [11] "Gryffindor"  "Gryffindor"  "Muggle"      "Muggle"      "Muggle"     
## [16] "Squib"       "Gryffindor"  "Beauxbatons" NA            "Slytherin"  
## [21] "Slytherin"   "Gryffindor"  "Gryffindor"  "Durmstrang"  "Durmstrang" 
## [26] "Slytherin"   "Gryffindor"  "Gryffindor"  "Gryffindor"  "Ravenclaw"  
## [31] "Ravenclaw"   "Gryffindor"  "Slytherin"   "Slytherin"   "Slytherin"  
## [36] "Beauxbatons" "Gryffindor"  NA            "Gryffindor"  "Gryffindor" 
## [41] "Gryffindor"  "Gryffindor"  "Ravenclaw"   "Muggle"      "Muggle"     
## [46] "Slytherin"   NA            "Slytherin"   "Hufflepuff"  "Slytherin"  
## [51] "Gryffindor"  "Gryffindor"  "Gryffindor"  "Gryffindor"  "Gryffindor" 
## [56] "Gryffindor"  "Gryffindor"  "Gryffindor"  "Gryffindor"  NA           
## [61] NA            NA            "Ravenclaw"   NA            NA           
## 
## $Color
##  [1] "darkgreen"      "darkred"        "darkred"        "blue2"         
##  [5] "darkgreen"      "darkgreen"      "white"          "white"         
##  [9] "cadetblue1"     "darkgoldenrod1" "darkred"        "darkred"       
## [13] "bisque"         "bisque"         "bisque"         "cornsilk3"     
## [17] "darkred"        "cadetblue1"     "white"          "darkgreen"     
## [21] "darkgreen"      "darkred"        "darkred"        "cornsilk4"     
## [25] "cornsilk4"      "darkgreen"      "darkred"        "darkred"       
## [29] "darkred"        "blue2"          "blue2"          "darkred"       
## [33] "darkgreen"      "darkgreen"      "darkgreen"      "cadetblue1"    
## [37] "darkred"        "white"          "darkred"        "darkred"       
## [41] "darkred"        "darkred"        "blue2"          "bisque"        
## [45] "bisque"         "darkgreen"      "white"          "darkgreen"     
## [49] "darkgoldenrod1" "darkgreen"      "darkred"        "darkred"       
## [53] "darkred"        "darkred"        "darkred"        "darkred"       
## [57] "darkred"        "darkred"        "darkred"        "white"         
## [61] "white"          "white"          "blue2"          "white"         
## [65] "white"
class(g11) #verifying that the graph is now under the class igraph for further analysis
## [1] "igraph"

Graphing the Network

Graphical representation of the network. The nodes are colored to represent the house to which the node belongs to. For example, characters from Gryffindor are colored in red (see legend for color associations). The Kamada Kawai layout was used becasue it was the best layout when wanting to separate the nodes as much as possible.

As we can see from the graph, most of the characters are Gryffindor, with Slytherin in second place. This isn’t surprising, as the main characters we all know from Harry Potter (Harry Potter, Hermione Granger and Ron Weasley) all belong to the Gryffindors.

In addition, the nodes on the outskirt of the network are the characters with less connections to the other characters. In other words, they know less people than any of the characters in the center of the graph.

color_vertices <- keys %>%
  group_by(House, Color) %>%
  summarise(n = n()) %>%
  filter(!is.na(Color)) #assigning a vertice's color to the its house and color within the dataset

mylayout <- layout.kamada.kawai(g1) #assign chosen layout to use to represent our network

par(mar=c(1,1,3,1)) #modify the layout of the RMarkdown

#plot the initial Harry Potter Network
plot(igraph::simplify(g1,edge.attr.comb = "min"),
     layout = mylayout,
     legend = TRUE,
     vertex.label = V(g1)$Character,
     vertex.color = V(g1)$Color, 
     vertex.frame.color = "gray", 
     vertex.label.color = "black", 
     vertex.label.cex = 0.6,
     vertex.label.dist=6,
     vertex.size = 20,
     asp = 0.75,
     rescale = FALSE,
     ylim = c(-5,3.5),
     xlim = c(-5,2))
legend("topleft", legend = c(NA, "", as.character(color_vertices$House)), pch = 19,
       col = c(NA, NA, color_vertices$Color), pt.cex = 1.5, cex = 0.65, bty = "n", ncol = 1,
       title = "")
legend("topleft", legend = "", cex = 0.95, bty = "n", ncol = 1,
       title = "Harry Potter's Network Character Connections")

Alignment Graph of the Characters

This graph gives us an overall view of each character’s alignment. Surprisingly, there is a higher number of “Good” characters amongst the 65 most important. “Evil” and “Neutral” characters seem to have the same proportion.

(The graph is interactive, meaning you can zoom in/out but also can click on specific nodes and move them around. Plus, if the graph does not show in the Markdown, make sure it is in the same zip folder that the R document)

keys_viz<-keys #make a copy of the keys dataframe to avoid writing over the original data

keys_viz$group <- keys$Alignment #group characters based on their alignment

visnet <- visNetwork(keys_viz, edges) #create a visNetwork

#plot the three alignments without any edges because we are interested in the distribution and not the relationship
visnet <- visGroups(visnet, groupname = "Evil", shape = "square",
                     color = list(background = "tomato", border="black"))
visnet <- visGroups(visnet, groupname = "Good", shape = "dot",       
                     color = list(background = "green", border="black"))
visnet <- visGroups(visnet, groupname = "Neutral", shape = "diamond",   
                     color = list(background = "gray", border="black"))
visLegend(visnet, main="Legend", position="right", ncol=1)

Degree Level and Distribution

Degree Level

The actors network has a mean degree value of 10.15. This means that actors within the network are on average directly connected with 10 other actors by virtue of knowing similar people. This seemingly small number is surprising considering this network is comprised of the most important characters in the movies.

It is clear from the histogram charts that the distribution doesn’t follow a normal distribution as it contains a right skew. The distribution in particular follows the so-called “Power Law” in that only a handful of articles have a high degree level.

With regards to standard deviation of the network, it is clear there is a fairly wide distribution (the standard deviation is actually just a bit smaller than the mean). This implies that while the overall average is quite low at approximately 10, there are almost more than a few characters who’s degrees are significantly higher or lower than this figure (shows high dispersity between the network degrees).

To have a better understanding of the first 15 degrees for each graph, we created an additional histogram representing the splitting of the degree distribution between 0 and 15 degrees for characters. From this, we can see that from 0 to 15 degrees, the frequencies are better distributed. Only degree 4 is considerably more frequent than the others.

deg<-igraph::degree(g11, mode = "total")
hist(deg, main="Histogram of Node Degree For Characters", ylim=c(0,30), col = "tomato") #plotting histogram of degree level frequencies

summary(deg) #gain information on the mean
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00    4.00    7.00   10.15   13.00   48.00
sd(deg) #gain information on the standard deviation
## [1] 9.569206
#when looking at the first 3 bars more in depth; range of 0 to 15 degrees
hist_1<-hist(deg, main="Histogram of Node Degree For Characters From 0-15 Degrees", xlim=c(0,15), ylim=c(0,30), breaks=888, col = "tomato") 

Degree Distribution

The degree distribution looks like a continuous logarithmic shaped where the cumulative frequency increases at a fast pace and then stagnates; it is discontinued at the beginning and then becomes constant when it becomes closer to 1. This confirms that most characters are within degree levels of 22. We can infer, that these characters, may represent secondary or tertiary roles in the movies, with only a few main character to the story line.

deg.dist <- igraph::degree_distribution(g11, cumulative=T, mode="all")

plot( x=0:max(deg), y=1-deg.dist, pch=19, cex=1.2, col="orange", xlab="Degree", ylab="Cumulative Frequency for Characters")

summary(deg.dist)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.01538 0.06154 0.07692 0.22763 0.32308 1.00000

Network Based on Level of Degree

Graphical representation of the network where the nodes are still colored to represent the house to which the node belongs to. However, now, the node sizes are based on the level of degree each character has (higher levels of degree have bigger node sizes).

As we can see from the graph, not surprisingly, the characters with the highest levels of degree are the main protagonists from the story line. This not only includes Harry, Hermione and Ron, but also Dumbledore and Voldemort. Later in the analysis, we will see which character has the highest degree between them.

par(mar=c(1,1,3,1)) #layout of the RMarkdown

plot(igraph::simplify(g1,edge.attr.comb = "min"),
     layout = mylayout,
     legend = TRUE,
     vertex.label = V(g1)$Character,
     vertex.color = V(g1)$Color, 
     vertex.frame.color = "gray", 
     vertex.label.color = "black", 
     vertex.size = deg*1.3,
     vertex.label.cex = 0.6,
     vertex.label.dist=3,
     asp = 0.75,
     rescale = FALSE,
     ylim = c(-5,3),
     xlim = c(-5,2))
legend("topleft", legend = c(NA, "", as.character(color_vertices$House)), pch = 19,
       col = c(NA, NA, color_vertices$Color), pt.cex = 1.5, cex = 0.65, bty = "n", ncol = 1,
       title = "")
legend("topleft", legend = "", cex = 0.95, bty = "n", ncol = 1,
       title = "Harry Potter's Character Level of Degree")

Network Properties

Connected Component (Graph Theory)

In graph theory, a connected component (or just component) of an undirected graph is a graph in which any two vertices are connected to each other by paths. The cohesion of a graph is the vertex connectivity of the graph. This is calculated by cohesion. In our case, we can see that our graph, from prior visualization was connected, but this result is also supported by the cohesion equation, which equals to 1. Thus, our whole network is confirmed as connected and every character in our network is somewhat connected to each other.

cohesion(g11, checks = TRUE) #calculate if our whole network is connected or not
## [1] 1

Network Average Path Length

The average path length describes the average distance between any two vertices (nodes).

The average path length of the Harry Potter network has a value of 2.02. This suggests that the network is on average not very dispersed, meaning that any two randomly selected characters of Harry Potter are closely related. This would make sense as this data represents the most important characters within the movies.

mean_distance(g11, directed=F) #calculate the average path length in an undirected graph
## [1] 2.028365

Graph Theory: Dijkstra

Now that we have calculated the average path length, the Dijkstra algorithm identifies the shortest paths in the network. Here are the steps to follow in order to obtain these paths:

First, to run the algorithm, we had to compute the Adjacency Matrix.

g11_edgelist<-as_edgelist(g11) #the adjacency matrix can only be calculated from a list of edges (conversts the grah's edges to a list)
g11_ajd<-get.adjacency(graph.edgelist(as.matrix(g11_edgelist), directed=FALSE)) #compute adjacency matrix
g11_ajd #by calling the adjacency matrix, we can see which characters have a connection (1) and when they don't (0) - sample of the matrix
## 65 x 65 sparse Matrix of class "dgCMatrix"
##    [[ suppressing 65 column names 'Regulus Arcturus Black', 'Sirius Black', 'Vincent Crabbe Sr.' ... ]]
##                                                                           
## Regulus Arcturus Black . 1 1 1 1 . . . . . . . . . . . . . . . . . . . . .
## Sirius Black           1 . . 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 .
## Vincent Crabbe Sr.     1 . . 1 1 . . . . 1 . . . 1 . . . 1 . . . . . . . .
## Bellatrix Lestrange    1 1 1 . 1 1 . . . 1 1 . . . 1 . . . 1 . . . . 1 1 .
## Lord Voldemort         1 1 1 1 . 1 . 1 1 1 1 1 1 1 1 1 1 1 1 . 1 1 1 1 1 .
## Albus Dumbledore       . 1 . 1 1 . 1 1 1 . . 1 1 1 1 1 1 1 . 1 1 1 1 1 1 .
## Argus Filch            . 1 . . . 1 . 1 . . . 1 . 1 1 1 . 1 . . 1 1 . . 1 .
## Hermione Granger       . 1 . . 1 1 1 . . . . 1 1 1 1 . . 1 . 1 1 1 1 1 1 1
## Remus Lupin            . 1 . . 1 1 . . . . . 1 . 1 1 1 . . 1 . 1 1 1 . 1 .
## Lucius Malfoy          . 1 1 1 1 . . . . . 1 . . . 1 . . . . 1 . . . 1 1 .
## Narcissa Malfoy        . 1 . 1 1 . . . . 1 . . . . . . . . . . . . . . . .
## Minerva McGonagall     . 1 . . 1 1 1 1 1 . . . . . 1 . . . . . . . . . 1 .
## Alastor Moody          . 1 . . 1 1 . 1 . . . . . . 1 . . . . 1 . . . 1 1 .
## Peter Pettigrew        . 1 1 . 1 1 1 1 1 . . . . . 1 1 1 . . . 1 1 1 . 1 .
## Harry Potter           . 1 . 1 1 1 1 1 1 1 . 1 1 1 . 1 1 1 . 1 1 1 1 1 1 .
## James Potter           . 1 . . 1 1 1 . 1 . . . . 1 1 . 1 . . . . . . . . .
## Lily Potter            . 1 . . 1 1 . . . . . . . 1 1 1 . 1 . . . . . . . .
## Severus Snape          . 1 1 . 1 1 1 1 . . . . . . 1 . 1 . . . 1 1 1 . 1 .
## Nymphadora Tonks       . 1 . 1 1 . . . 1 . . . . . . . . . . . . . . . . .
## Arthur Weasley         . 1 . . . 1 . 1 . 1 . . 1 . 1 . . . . . 1 1 1 1 1 .
## Fred Weasley           . 1 . . 1 1 1 1 1 . . . . 1 1 . . 1 . 1 . 1 1 1 1 .
## George Weasley         . 1 . . 1 1 1 1 1 . . . . 1 1 . . 1 . 1 1 . 1 1 1 .
## Ginny Weasley          . 1 . . 1 1 . 1 1 . . . . 1 1 . . 1 . 1 1 1 . 1 1 .
## Molly Weasley          . 1 . 1 1 1 . 1 . 1 . . 1 . 1 . . . . 1 1 1 1 . 1 .
## Ron Weasley            . 1 . 1 1 1 1 1 1 1 . 1 1 1 1 . . 1 . 1 1 1 1 1 . 1
## Lavender Brown         . . . . . . . 1 . . . . . . . . . . . . . . . . 1 .
## Seamus Finnigan        . . . . . . . 1 . . . . . . 1 . . . . . . . 1 . 1 1
## Neville Longbottom     . . . . 1 . . 1 . . . . . . 1 . . . . . . . . . 1 1
## Cho Chang              . . . . 1 . . 1 . . . . . . 1 . . . . . . . . . 1 .
## Cedric Diggory         . . . . 1 . . . . . . . . . 1 . . . . . . . . . . .
## Vincent Crabbe         . . 1 . . . . 1 . . . . . . 1 . . . . . . . . . 1 .
## Bartemius Crouch Sr.   . . 1 . . . . . . . . . . . . . . . . . . . . . . .
## Goyle Sr.              . . 1 . 1 . . . . . . . . . . . . . . . . . . . . .
## Gregory Goyle          . . . . 1 . . 1 . . . . . . 1 . . . . . . . . . 1 .
## Draco Malfoy           . . . . . . . 1 . 1 1 . . . 1 . . . . . . . . . 1 .
## Dolores Janes Umbridge . . . . . 1 1 1 . . . 1 . . 1 . . . . . . . . . 1 .
## Bartemius Crouch Jr.   . . . . 1 . . 1 . . . 1 1 1 1 . . 1 . . . . . . . .
## Igor Karkaroff         . . . . 1 . . . . . . . . . . . . . . . . . . . . .
## Percy Weasley          . . . . . 1 . . . . . . . . . . . . . 1 1 1 1 1 1 .
## Fleur Delacour         . . . 1 . . . 1 . . . . 1 . 1 . . . . . . . 1 1 1 .
## Viktor Krum            . . . . . . . 1 . . . . . . 1 . . . . . . . . . . .
## Olympe Maxime          . . . . . 1 . . . . . . . . . . . . . . . . . . . .
## Bill Weasley           . . . . 1 1 . 1 . . . . . . 1 . . . . 1 1 1 1 1 1 .
## Aberforth Dumbledore   . . . . . 1 . 1 . . . . . . 1 . . . . . . . . . 1 .
## Dobby                  . . . 1 . . . 1 . 1 . . . . 1 . . . . . . . . . 1 .
## Petunia Dursley        . . . . . 1 . . . . . . . . 1 . 1 . . . . . . . . .
## Vernon Dursley         . . . . . 1 . . . . . . . . 1 . . . . . . . . . . .
## Nicolas Flamel         . . . . . 1 . . . . . . . . . . . . . . . . . . . .
## Cornelius Fudge        . . . . . 1 . . . 1 . . . . 1 . . . . 1 . . . . . .
## Rubeus Hagrid          . . . . 1 1 1 1 . . . 1 . . 1 . . 1 . . . . . . 1 .
## Quirinus Quirrell      . . . . 1 1 . 1 . . . . . . 1 . . . . . . . . . . .
## Rita Skeeter           . . . . . 1 . . . . . . . . 1 . . . . . . . . . . .
## Charlie Weasley        . . . . 1 1 . 1 . . . . . . 1 . . . . 1 1 1 1 1 1 .
## Dudley Dursley         . . . . . . . . . . . . . . 1 . . . . . . . . . . .
## Luna Lovegood          . . . . . . . 1 . . . . . . 1 . . . . . . . . . 1 .
## Fluffy                 . . . . . . . 1 . . . . . . 1 . . . . . . . . . 1 .
## Aragog                 . . . . . . . 1 . . . . . . 1 . . . . . . . . . 1 .
## Grawp                  . . . . . . . 1 . . . . . . 1 . . . . . . . . . 1 .
## Alice Longbottom       . . . . . . . . . . . . . . . . . . . . . . . . . .
## Frank Longbottom       . . . . 1 . . . . . . . . . . . . . . . . . . . . .
## Xenophilius Lovegood   . . . . . . . . . . . . . . . . . . . . . . . . . .
## Hedwig                 . . . . . . . . . . . . . . 1 . . . . . . . . . . .
## Moaning Myrtle         . . . . . . . . . . . . . . 1 . . . . . . . . . . .
## Tom Riddle Sr.         . . . . 1 . . . . . . . . . . . . . . . . . . . . .
## Mary Riddle            . . . . 1 . . . . . . . . . . . . . . . . . . . . .
##                                                                           
## Regulus Arcturus Black . . . . . . . . . . . . . . . . . . . . . . . . . .
## Sirius Black           . . . . . . . . . . . . . . . . . . . . . . . . . .
## Vincent Crabbe Sr.     . . . . 1 1 1 . . . . . . . . . . . . . . . . . . .
## Bellatrix Lestrange    . . . . . . . . . . . . . 1 . . . . 1 . . . . . . .
## Lord Voldemort         . 1 1 1 . . 1 1 . . 1 1 . . . . 1 . . . . . . 1 1 .
## Albus Dumbledore       . . . . . . . . . 1 . . 1 . . 1 1 1 . 1 1 1 1 1 1 1
## Argus Filch            . . . . . . . . . 1 . . . . . . . . . . . . . 1 . .
## Hermione Granger       1 1 1 . 1 . . 1 1 1 1 . . 1 1 . 1 1 1 . . . . 1 1 .
## Remus Lupin            . . . . . . . . . . . . . . . . . . . . . . . . . .
## Lucius Malfoy          . . . . . . . . 1 . . . . . . . . . 1 . . . 1 . . .
## Narcissa Malfoy        . . . . . . . . 1 . . . . . . . . . . . . . . . . .
## Minerva McGonagall     . . . . . . . . . 1 1 . . . . . . . . . . . . 1 . .
## Alastor Moody          . . . . . . . . . . 1 . . 1 . . . . . . . . . . . .
## Peter Pettigrew        . . . . . . . . . . 1 . . . . . . . . . . . . . . .
## Harry Potter           1 1 1 1 1 . . 1 1 1 1 . . 1 1 . 1 1 1 1 1 . 1 1 1 1
## James Potter           . . . . . . . . . . . . . . . . . . . . . . . . . .
## Lily Potter            . . . . . . . . . . . . . . . . . . . 1 . . . . . .
## Severus Snape          . . . . . . . . . . 1 . . . . . . . . . . . . 1 . .
## Nymphadora Tonks       . . . . . . . . . . . . . . . . . . . . . . . . . .
## Arthur Weasley         . . . . . . . . . . . . 1 . . . 1 . . . . . 1 . . .
## Fred Weasley           . . . . . . . . . . . . 1 . . . 1 . . . . . . . . .
## George Weasley         . . . . . . . . . . . . 1 . . . 1 . . . . . . . . .
## Ginny Weasley          1 . . . . . . . . . . . 1 1 . . 1 . . . . . . . . .
## Molly Weasley          . . . . . . . . . . . . 1 1 . . 1 . . . . . . . . .
## Ron Weasley            1 1 1 . 1 . . 1 1 1 . . 1 1 . . 1 1 1 . . . . 1 . .
## Lavender Brown         1 1 . . . . . . . . . . . . . . . . . . . . . . . .
## Seamus Finnigan        . 1 1 . . . . . . . . . . . . . . . . . . . . . . .
## Neville Longbottom     1 . 1 . . . . . 1 . 1 . . 1 . . . . . . . . . 1 . .
## Cho Chang              1 1 . 1 . . . . . . . . . . . . . . . . . . . . . .
## Cedric Diggory         . . 1 . . . . . . . . . . . 1 . . . . . . . . . . .
## Vincent Crabbe         . . . . . . . 1 1 1 . . . . . . . . . . . . . . . .
## Bartemius Crouch Sr.   . . . . . . . . . . 1 1 1 . . . . . . . . . . . . .
## Goyle Sr.              . . . . . . . 1 . . . . . . . . . . . . . . . . . .
## Gregory Goyle          . . . . 1 . 1 . 1 . . . . . . . . . . . . . . . . .
## Draco Malfoy           . 1 . . 1 . . 1 . . . . . . . . . . 1 . . . . . . .
## Dolores Janes Umbridge . . . . 1 . . . . . . . . . . . . . . . . . 1 . . .
## Bartemius Crouch Jr.   . 1 . . . 1 . . . . . . . . . . . . . . . . . . . .
## Igor Karkaroff         . . . . . 1 . . . . . . . . 1 1 . . . . . . . . . .
## Percy Weasley          . . . . . 1 . . . . . . . . . . 1 . . . . . 1 . . .
## Fleur Delacour         . 1 . . . . . . . . . . . . 1 1 1 . . . . . . . . .
## Viktor Krum            . . . 1 . . . . . . . 1 . 1 . . . . . . . . . . . .
## Olympe Maxime          . . . . . . . . . . . 1 . 1 . . . . . . . . . 1 . .
## Bill Weasley           . . . . . . . . . . . . 1 1 . . . . . . . . . . . .
## Aberforth Dumbledore   . . . . . . . . . . . . . . . . . . 1 . . . . . . .
## Dobby                  . . . . . . . . 1 . . . . . . . . 1 . . . . . . . .
## Petunia Dursley        . . . . . . . . . . . . . . . . . . . . 1 . . . . .
## Vernon Dursley         . . . . . . . . . . . . . . . . . . . 1 . . . . . .
## Nicolas Flamel         . . . . . . . . . . . . . . . . . . . . . . . . . .
## Cornelius Fudge        . . . . . . . . . 1 . . 1 . . . . . . . . . . . . .
## Rubeus Hagrid          . 1 . . . . . . . . . . . . . 1 . . . . . . . . . .
## Quirinus Quirrell      . . . . . . . . . . . . . . . . . . . . . . . . . .
## Rita Skeeter           . . . . . . . . . . . . . . . . . . . . . . . . . .
## Charlie Weasley        . . . . . . . . . . . . 1 . . . 1 . . . . . . . . .
## Dudley Dursley         . . . . . . . . . . . . . . . . . . . 1 1 . . 1 . .
## Luna Lovegood          1 1 . . . . . . . . . . . . . . . . . . . . . . . .
## Fluffy                 . . . . . . . . . . . . . . . . . . . . . . . 1 . .
## Aragog                 . . . . . . . . . . . . . . . . . . . . . . . 1 . .
## Grawp                  . . . . . . . . . . . . . . . . . . . . . . . 1 . .
## Alice Longbottom       . 1 . . . . . . . . . . . . . . . . . . . . . . . .
## Frank Longbottom       . 1 . . . . . . . . . . . . . . . . . . . . . . . .
## Xenophilius Lovegood   . . . . . . . . . . . . . . . . . . . . . . . . . .
## Hedwig                 . . . . . . . . . . . . . . . . . . . . . . . . . .
## Moaning Myrtle         . . . . . . . . . . . . . . . . . . . . . . . . . .
## Tom Riddle Sr.         . . . . . . . . . . . . . . . . . . . . . . . . . .
## Mary Riddle            . . . . . . . . . . . . . . . . . . . . . . . . . .
##                                                 
## Regulus Arcturus Black . . . . . . . . . . . . .
## Sirius Black           . . . . . . . . . . . . .
## Vincent Crabbe Sr.     . . . . . . . . . . . . .
## Bellatrix Lestrange    . . . . . . . . . . . . .
## Lord Voldemort         1 . . . . . . 1 . . . 1 1
## Albus Dumbledore       1 . . . . . . . . . . . .
## Argus Filch            . . . . . . . . . . . . .
## Hermione Granger       1 . 1 1 1 1 . . . . . . .
## Remus Lupin            . . . . . . . . . . . . .
## Lucius Malfoy          . . . . . . . . . . . . .
## Narcissa Malfoy        . . . . . . . . . . . . .
## Minerva McGonagall     . . . . . . . . . . . . .
## Alastor Moody          . . . . . . . . . . . . .
## Peter Pettigrew        . . . . . . . . . . . . .
## Harry Potter           1 1 1 1 1 1 . . . 1 1 . .
## James Potter           . . . . . . . . . . . . .
## Lily Potter            . . . . . . . . . . . . .
## Severus Snape          . . . . . . . . . . . . .
## Nymphadora Tonks       . . . . . . . . . . . . .
## Arthur Weasley         1 . . . . . . . . . . . .
## Fred Weasley           1 . . . . . . . . . . . .
## George Weasley         1 . . . . . . . . . . . .
## Ginny Weasley          1 . . . . . . . . . . . .
## Molly Weasley          1 . . . . . . . . . . . .
## Ron Weasley            1 . 1 1 1 1 . . . . . . .
## Lavender Brown         . . . . . . . . . . . . .
## Seamus Finnigan        . . 1 . . . . . . . . . .
## Neville Longbottom     . . 1 . . . 1 1 . . . . .
## Cho Chang              . . . . . . . . . . . . .
## Cedric Diggory         . . . . . . . . . . . . .
## Vincent Crabbe         . . . . . . . . . . . . .
## Bartemius Crouch Sr.   . . . . . . . . . . . . .
## Goyle Sr.              . . . . . . . . . . . . .
## Gregory Goyle          . . . . . . . . . . . . .
## Draco Malfoy           . . . . . . . . . . . . .
## Dolores Janes Umbridge . . . . . . . . . . . . .
## Bartemius Crouch Jr.   . . . . . . . . . . . . .
## Igor Karkaroff         . . . . . . . . . . . . .
## Percy Weasley          1 . . . . . . . . . . . .
## Fleur Delacour         . . . . . . . . . . . . .
## Viktor Krum            . . . . . . . . . . . . .
## Olympe Maxime          . . . . . . . . . . . . .
## Bill Weasley           1 . . . . . . . . . . . .
## Aberforth Dumbledore   . . . . . . . . . . . . .
## Dobby                  . . . . . . . . . . . . .
## Petunia Dursley        . 1 . . . . . . . . . . .
## Vernon Dursley         . 1 . . . . . . . . . . .
## Nicolas Flamel         . . . . . . . . . . . . .
## Cornelius Fudge        . . . . . . . . . . . . .
## Rubeus Hagrid          . 1 . 1 1 1 . . . . . . .
## Quirinus Quirrell      . . . . . . . . . . . . .
## Rita Skeeter           . . . . . . . . . . . . .
## Charlie Weasley        . . . . . . . . . . . . .
## Dudley Dursley         . . . . . . . . . . . . .
## Luna Lovegood          . . . . . . . . 1 . . . .
## Fluffy                 . . . . . . . . . . . . .
## Aragog                 . . . . . . . . . . . . .
## Grawp                  . . . . . . . . . . . . .
## Alice Longbottom       . . . . . . . 1 . . . . .
## Frank Longbottom       . . . . . . 1 . . . . . .
## Xenophilius Lovegood   . . 1 . . . . . . . . . .
## Hedwig                 . . . . . . . . . . . . .
## Moaning Myrtle         . . . . . . . . . . . . .
## Tom Riddle Sr.         . . . . . . . . . . . . 1
## Mary Riddle            . . . . . . . . . . . 1 .

Then, we were able to run Dijkstra, from which we obtained the matrix of the shortest paths. On average, the shortest paths are of 2, which supports the fact that our average path length is equal to 2. We can see that there is also only one shortest path equivalent to 4, which we can assume is our diameter (this will be confirmed below).

graph_ajd<-graph.adjacency(g11_ajd) #convert matrix adjacency to a graph for which we can then obtain the shortest paths matrix (below) when using the dijkstra algorithm

s.paths <- shortest.paths(graph_ajd, algorithm = "dijkstra")
s.paths
##                        Regulus Arcturus Black Sirius Black
## Regulus Arcturus Black                      0            1
## Sirius Black                                1            0
## Vincent Crabbe Sr.                          1            2
## Bellatrix Lestrange                         1            1
## Lord Voldemort                              1            1
## Albus Dumbledore                            2            1
## Argus Filch                                 2            1
## Hermione Granger                            2            1
## Remus Lupin                                 2            1
## Lucius Malfoy                               2            1
## Narcissa Malfoy                             2            1
## Minerva McGonagall                          2            1
## Alastor Moody                               2            1
## Peter Pettigrew                             2            1
## Harry Potter                                2            1
## James Potter                                2            1
## Lily Potter                                 2            1
## Severus Snape                               2            1
## Nymphadora Tonks                            2            1
## Arthur Weasley                              2            1
## Fred Weasley                                2            1
## George Weasley                              2            1
## Ginny Weasley                               2            1
## Molly Weasley                               2            1
## Ron Weasley                                 2            1
## Lavender Brown                              3            2
## Seamus Finnigan                             3            2
## Neville Longbottom                          2            2
## Cho Chang                                   2            2
## Cedric Diggory                              2            2
## Vincent Crabbe                              2            2
## Bartemius Crouch Sr.                        2            3
## Goyle Sr.                                   2            2
## Gregory Goyle                               2            2
## Draco Malfoy                                3            2
## Dolores Janes Umbridge                      3            2
## Bartemius Crouch Jr.                        2            2
## Igor Karkaroff                              2            2
## Percy Weasley                               3            2
## Fleur Delacour                              2            2
## Viktor Krum                                 3            2
## Olympe Maxime                               3            2
## Bill Weasley                                2            2
## Aberforth Dumbledore                        3            2
## Dobby                                       2            2
## Petunia Dursley                             3            2
## Vernon Dursley                              3            2
## Nicolas Flamel                              3            2
## Cornelius Fudge                             3            2
## Rubeus Hagrid                               2            2
## Quirinus Quirrell                           2            2
## Rita Skeeter                                3            2
## Charlie Weasley                             2            2
## Dudley Dursley                              3            2
## Luna Lovegood                               3            2
## Fluffy                                      3            2
## Aragog                                      3            2
## Grawp                                       3            2
## Alice Longbottom                            3            3
## Frank Longbottom                            2            2
## Xenophilius Lovegood                        4            3
## Hedwig                                      3            2
## Moaning Myrtle                              3            2
## Tom Riddle Sr.                              2            2
## Mary Riddle                                 2            2
##                        Vincent Crabbe Sr. Bellatrix Lestrange
## Regulus Arcturus Black                  1                   1
## Sirius Black                            2                   1
## Vincent Crabbe Sr.                      0                   1
## Bellatrix Lestrange                     1                   0
## Lord Voldemort                          1                   1
## Albus Dumbledore                        2                   1
## Argus Filch                             2                   2
## Hermione Granger                        2                   2
## Remus Lupin                             2                   2
## Lucius Malfoy                           1                   1
## Narcissa Malfoy                         2                   1
## Minerva McGonagall                      2                   2
## Alastor Moody                           2                   2
## Peter Pettigrew                         1                   2
## Harry Potter                            2                   1
## James Potter                            2                   2
## Lily Potter                             2                   2
## Severus Snape                           1                   2
## Nymphadora Tonks                        2                   1
## Arthur Weasley                          2                   2
## Fred Weasley                            2                   2
## George Weasley                          2                   2
## Ginny Weasley                           2                   2
## Molly Weasley                           2                   1
## Ron Weasley                             2                   1
## Lavender Brown                          3                   2
## Seamus Finnigan                         3                   2
## Neville Longbottom                      2                   2
## Cho Chang                               2                   2
## Cedric Diggory                          2                   2
## Vincent Crabbe                          1                   2
## Bartemius Crouch Sr.                    1                   2
## Goyle Sr.                               1                   2
## Gregory Goyle                           2                   2
## Draco Malfoy                            2                   2
## Dolores Janes Umbridge                  2                   2
## Bartemius Crouch Jr.                    2                   2
## Igor Karkaroff                          2                   2
## Percy Weasley                           2                   2
## Fleur Delacour                          2                   1
## Viktor Krum                             3                   2
## Olympe Maxime                           3                   2
## Bill Weasley                            2                   2
## Aberforth Dumbledore                    3                   2
## Dobby                                   2                   1
## Petunia Dursley                         3                   2
## Vernon Dursley                          3                   2
## Nicolas Flamel                          3                   2
## Cornelius Fudge                         2                   2
## Rubeus Hagrid                           2                   2
## Quirinus Quirrell                       2                   2
## Rita Skeeter                            3                   2
## Charlie Weasley                         2                   2
## Dudley Dursley                          3                   2
## Luna Lovegood                           3                   2
## Fluffy                                  3                   2
## Aragog                                  3                   2
## Grawp                                   3                   2
## Alice Longbottom                        3                   3
## Frank Longbottom                        2                   2
## Xenophilius Lovegood                    4                   3
## Hedwig                                  3                   2
## Moaning Myrtle                          3                   2
## Tom Riddle Sr.                          2                   2
## Mary Riddle                             2                   2
##                        Lord Voldemort Albus Dumbledore Argus Filch
## Regulus Arcturus Black              1                2           2
## Sirius Black                        1                1           1
## Vincent Crabbe Sr.                  1                2           2
## Bellatrix Lestrange                 1                1           2
## Lord Voldemort                      0                1           2
## Albus Dumbledore                    1                0           1
## Argus Filch                         2                1           0
## Hermione Granger                    1                1           1
## Remus Lupin                         1                1           2
## Lucius Malfoy                       1                2           2
## Narcissa Malfoy                     1                2           2
## Minerva McGonagall                  1                1           1
## Alastor Moody                       1                1           2
## Peter Pettigrew                     1                1           1
## Harry Potter                        1                1           1
## James Potter                        1                1           1
## Lily Potter                         1                1           2
## Severus Snape                       1                1           1
## Nymphadora Tonks                    1                2           2
## Arthur Weasley                      2                1           2
## Fred Weasley                        1                1           1
## George Weasley                      1                1           1
## Ginny Weasley                       1                1           2
## Molly Weasley                       1                1           2
## Ron Weasley                         1                1           1
## Lavender Brown                      2                2           2
## Seamus Finnigan                     2                2           2
## Neville Longbottom                  1                2           2
## Cho Chang                           1                2           2
## Cedric Diggory                      1                2           2
## Vincent Crabbe                      2                2           2
## Bartemius Crouch Sr.                2                2           3
## Goyle Sr.                           1                2           3
## Gregory Goyle                       1                2           2
## Draco Malfoy                        2                2           2
## Dolores Janes Umbridge              2                1           1
## Bartemius Crouch Jr.                1                2           2
## Igor Karkaroff                      1                2           3
## Percy Weasley                       2                1           2
## Fleur Delacour                      2                2           2
## Viktor Krum                         2                2           2
## Olympe Maxime                       2                1           2
## Bill Weasley                        1                1           2
## Aberforth Dumbledore                2                1           2
## Dobby                               2                2           2
## Petunia Dursley                     2                1           2
## Vernon Dursley                      2                1           2
## Nicolas Flamel                      2                1           2
## Cornelius Fudge                     2                1           2
## Rubeus Hagrid                       1                1           1
## Quirinus Quirrell                   1                1           2
## Rita Skeeter                        2                1           2
## Charlie Weasley                     1                1           2
## Dudley Dursley                      2                2           2
## Luna Lovegood                       2                2           2
## Fluffy                              2                2           2
## Aragog                              2                2           2
## Grawp                               2                2           2
## Alice Longbottom                    2                3           3
## Frank Longbottom                    1                2           3
## Xenophilius Lovegood                3                3           3
## Hedwig                              2                2           2
## Moaning Myrtle                      2                2           2
## Tom Riddle Sr.                      1                2           3
## Mary Riddle                         1                2           3
##                        Hermione Granger Remus Lupin Lucius Malfoy
## Regulus Arcturus Black                2           2             2
## Sirius Black                          1           1             1
## Vincent Crabbe Sr.                    2           2             1
## Bellatrix Lestrange                   2           2             1
## Lord Voldemort                        1           1             1
## Albus Dumbledore                      1           1             2
## Argus Filch                           1           2             2
## Hermione Granger                      0           2             2
## Remus Lupin                           2           0             2
## Lucius Malfoy                         2           2             0
## Narcissa Malfoy                       2           2             1
## Minerva McGonagall                    1           1             2
## Alastor Moody                         1           2             2
## Peter Pettigrew                       1           1             2
## Harry Potter                          1           1             1
## James Potter                          2           1             2
## Lily Potter                           2           2             2
## Severus Snape                         1           2             2
## Nymphadora Tonks                      2           1             2
## Arthur Weasley                        1           2             1
## Fred Weasley                          1           1             2
## George Weasley                        1           1             2
## Ginny Weasley                         1           1             2
## Molly Weasley                         1           2             1
## Ron Weasley                           1           1             1
## Lavender Brown                        1           2             2
## Seamus Finnigan                       1           2             2
## Neville Longbottom                    1           2             2
## Cho Chang                             1           2             2
## Cedric Diggory                        2           2             2
## Vincent Crabbe                        1           2             2
## Bartemius Crouch Sr.                  2           3             2
## Goyle Sr.                             2           2             2
## Gregory Goyle                         1           2             2
## Draco Malfoy                          1           2             1
## Dolores Janes Umbridge                1           2             2
## Bartemius Crouch Jr.                  1           2             2
## Igor Karkaroff                        2           2             2
## Percy Weasley                         2           2             2
## Fleur Delacour                        1           2             2
## Viktor Krum                           1           2             2
## Olympe Maxime                         2           2             3
## Bill Weasley                          1           2             2
## Aberforth Dumbledore                  1           2             2
## Dobby                                 1           2             1
## Petunia Dursley                       2           2             2
## Vernon Dursley                        2           2             2
## Nicolas Flamel                        2           2             3
## Cornelius Fudge                       2           2             1
## Rubeus Hagrid                         1           2             2
## Quirinus Quirrell                     1           2             2
## Rita Skeeter                          2           2             2
## Charlie Weasley                       1           2             2
## Dudley Dursley                        2           2             2
## Luna Lovegood                         1           2             2
## Fluffy                                1           2             2
## Aragog                                1           2             2
## Grawp                                 1           2             2
## Alice Longbottom                      2           3             3
## Frank Longbottom                      2           2             2
## Xenophilius Lovegood                  2           3             3
## Hedwig                                2           2             2
## Moaning Myrtle                        2           2             2
## Tom Riddle Sr.                        2           2             2
## Mary Riddle                           2           2             2
##                        Narcissa Malfoy Minerva McGonagall Alastor Moody
## Regulus Arcturus Black               2                  2             2
## Sirius Black                         1                  1             1
## Vincent Crabbe Sr.                   2                  2             2
## Bellatrix Lestrange                  1                  2             2
## Lord Voldemort                       1                  1             1
## Albus Dumbledore                     2                  1             1
## Argus Filch                          2                  1             2
## Hermione Granger                     2                  1             1
## Remus Lupin                          2                  1             2
## Lucius Malfoy                        1                  2             2
## Narcissa Malfoy                      0                  2             2
## Minerva McGonagall                   2                  0             2
## Alastor Moody                        2                  2             0
## Peter Pettigrew                      2                  2             2
## Harry Potter                         2                  1             1
## James Potter                         2                  2             2
## Lily Potter                          2                  2             2
## Severus Snape                        2                  2             2
## Nymphadora Tonks                     2                  2             2
## Arthur Weasley                       2                  2             1
## Fred Weasley                         2                  2             2
## George Weasley                       2                  2             2
## Ginny Weasley                        2                  2             2
## Molly Weasley                        2                  2             1
## Ron Weasley                          2                  1             1
## Lavender Brown                       3                  2             2
## Seamus Finnigan                      3                  2             2
## Neville Longbottom                   2                  2             2
## Cho Chang                            2                  2             2
## Cedric Diggory                       2                  2             2
## Vincent Crabbe                       2                  2             2
## Bartemius Crouch Sr.                 3                  2             2
## Goyle Sr.                            2                  2             2
## Gregory Goyle                        2                  2             2
## Draco Malfoy                         1                  2             2
## Dolores Janes Umbridge               3                  1             2
## Bartemius Crouch Jr.                 2                  1             1
## Igor Karkaroff                       2                  2             2
## Percy Weasley                        3                  2             2
## Fleur Delacour                       2                  2             1
## Viktor Krum                          3                  2             2
## Olympe Maxime                        3                  2             2
## Bill Weasley                         2                  2             2
## Aberforth Dumbledore                 3                  2             2
## Dobby                                2                  2             2
## Petunia Dursley                      3                  2             2
## Vernon Dursley                       3                  2             2
## Nicolas Flamel                       3                  2             2
## Cornelius Fudge                      2                  2             2
## Rubeus Hagrid                        2                  1             2
## Quirinus Quirrell                    2                  2             2
## Rita Skeeter                         3                  2             2
## Charlie Weasley                      2                  2             2
## Dudley Dursley                       3                  2             2
## Luna Lovegood                        3                  2             2
## Fluffy                               3                  2             2
## Aragog                               3                  2             2
## Grawp                                3                  2             2
## Alice Longbottom                     3                  3             3
## Frank Longbottom                     2                  2             2
## Xenophilius Lovegood                 4                  3             3
## Hedwig                               3                  2             2
## Moaning Myrtle                       3                  2             2
## Tom Riddle Sr.                       2                  2             2
## Mary Riddle                          2                  2             2
##                        Peter Pettigrew Harry Potter James Potter
## Regulus Arcturus Black               2            2            2
## Sirius Black                         1            1            1
## Vincent Crabbe Sr.                   1            2            2
## Bellatrix Lestrange                  2            1            2
## Lord Voldemort                       1            1            1
## Albus Dumbledore                     1            1            1
## Argus Filch                          1            1            1
## Hermione Granger                     1            1            2
## Remus Lupin                          1            1            1
## Lucius Malfoy                        2            1            2
## Narcissa Malfoy                      2            2            2
## Minerva McGonagall                   2            1            2
## Alastor Moody                        2            1            2
## Peter Pettigrew                      0            1            1
## Harry Potter                         1            0            1
## James Potter                         1            1            0
## Lily Potter                          1            1            1
## Severus Snape                        2            1            2
## Nymphadora Tonks                     2            2            2
## Arthur Weasley                       2            1            2
## Fred Weasley                         1            1            2
## George Weasley                       1            1            2
## Ginny Weasley                        1            1            2
## Molly Weasley                        2            1            2
## Ron Weasley                          1            1            2
## Lavender Brown                       2            2            3
## Seamus Finnigan                      2            1            2
## Neville Longbottom                   2            1            2
## Cho Chang                            2            1            2
## Cedric Diggory                       2            1            2
## Vincent Crabbe                       2            1            2
## Bartemius Crouch Sr.                 2            2            3
## Goyle Sr.                            2            2            2
## Gregory Goyle                        2            1            2
## Draco Malfoy                         2            1            2
## Dolores Janes Umbridge               2            1            2
## Bartemius Crouch Jr.                 1            1            2
## Igor Karkaroff                       2            2            2
## Percy Weasley                        2            2            2
## Fleur Delacour                       2            1            2
## Viktor Krum                          2            1            2
## Olympe Maxime                        2            2            2
## Bill Weasley                         2            1            2
## Aberforth Dumbledore                 2            1            2
## Dobby                                2            1            2
## Petunia Dursley                      2            1            2
## Vernon Dursley                       2            1            2
## Nicolas Flamel                       2            2            2
## Cornelius Fudge                      2            1            2
## Rubeus Hagrid                        2            1            2
## Quirinus Quirrell                    2            1            2
## Rita Skeeter                         2            1            2
## Charlie Weasley                      2            1            2
## Dudley Dursley                       2            1            2
## Luna Lovegood                        2            1            2
## Fluffy                               2            1            2
## Aragog                               2            1            2
## Grawp                                2            1            2
## Alice Longbottom                     3            2            3
## Frank Longbottom                     2            2            2
## Xenophilius Lovegood                 3            2            3
## Hedwig                               2            1            2
## Moaning Myrtle                       2            1            2
## Tom Riddle Sr.                       2            2            2
## Mary Riddle                          2            2            2
##                        Lily Potter Severus Snape Nymphadora Tonks
## Regulus Arcturus Black           2             2                2
## Sirius Black                     1             1                1
## Vincent Crabbe Sr.               2             1                2
## Bellatrix Lestrange              2             2                1
## Lord Voldemort                   1             1                1
## Albus Dumbledore                 1             1                2
## Argus Filch                      2             1                2
## Hermione Granger                 2             1                2
## Remus Lupin                      2             2                1
## Lucius Malfoy                    2             2                2
## Narcissa Malfoy                  2             2                2
## Minerva McGonagall               2             2                2
## Alastor Moody                    2             2                2
## Peter Pettigrew                  1             2                2
## Harry Potter                     1             1                2
## James Potter                     1             2                2
## Lily Potter                      0             1                2
## Severus Snape                    1             0                2
## Nymphadora Tonks                 2             2                0
## Arthur Weasley                   2             2                2
## Fred Weasley                     2             1                2
## George Weasley                   2             1                2
## Ginny Weasley                    2             1                2
## Molly Weasley                    2             2                2
## Ron Weasley                      2             1                2
## Lavender Brown                   3             2                3
## Seamus Finnigan                  2             2                3
## Neville Longbottom               2             2                2
## Cho Chang                        2             2                2
## Cedric Diggory                   2             2                2
## Vincent Crabbe                   2             2                3
## Bartemius Crouch Sr.             3             2                3
## Goyle Sr.                        2             2                2
## Gregory Goyle                    2             2                2
## Draco Malfoy                     2             2                3
## Dolores Janes Umbridge           2             2                3
## Bartemius Crouch Jr.             2             1                2
## Igor Karkaroff                   2             2                2
## Percy Weasley                    2             2                3
## Fleur Delacour                   2             2                2
## Viktor Krum                      2             2                3
## Olympe Maxime                    2             2                3
## Bill Weasley                     2             2                2
## Aberforth Dumbledore             2             2                3
## Dobby                            2             2                2
## Petunia Dursley                  1             2                3
## Vernon Dursley                   2             2                3
## Nicolas Flamel                   2             2                3
## Cornelius Fudge                  2             2                3
## Rubeus Hagrid                    2             1                2
## Quirinus Quirrell                2             2                2
## Rita Skeeter                     2             2                3
## Charlie Weasley                  2             2                2
## Dudley Dursley                   2             2                3
## Luna Lovegood                    2             2                3
## Fluffy                           2             2                3
## Aragog                           2             2                3
## Grawp                            2             2                3
## Alice Longbottom                 3             3                3
## Frank Longbottom                 2             2                2
## Xenophilius Lovegood             3             3                4
## Hedwig                           2             2                3
## Moaning Myrtle                   2             2                3
## Tom Riddle Sr.                   2             2                2
## Mary Riddle                      2             2                2
##                        Arthur Weasley Fred Weasley George Weasley
## Regulus Arcturus Black              2            2              2
## Sirius Black                        1            1              1
## Vincent Crabbe Sr.                  2            2              2
## Bellatrix Lestrange                 2            2              2
## Lord Voldemort                      2            1              1
## Albus Dumbledore                    1            1              1
## Argus Filch                         2            1              1
## Hermione Granger                    1            1              1
## Remus Lupin                         2            1              1
## Lucius Malfoy                       1            2              2
## Narcissa Malfoy                     2            2              2
## Minerva McGonagall                  2            2              2
## Alastor Moody                       1            2              2
## Peter Pettigrew                     2            1              1
## Harry Potter                        1            1              1
## James Potter                        2            2              2
## Lily Potter                         2            2              2
## Severus Snape                       2            1              1
## Nymphadora Tonks                    2            2              2
## Arthur Weasley                      0            1              1
## Fred Weasley                        1            0              1
## George Weasley                      1            1              0
## Ginny Weasley                       1            1              1
## Molly Weasley                       1            1              1
## Ron Weasley                         1            1              1
## Lavender Brown                      2            2              2
## Seamus Finnigan                     2            2              2
## Neville Longbottom                  2            2              2
## Cho Chang                           2            2              2
## Cedric Diggory                      2            2              2
## Vincent Crabbe                      2            2              2
## Bartemius Crouch Sr.                2            2              2
## Goyle Sr.                           3            2              2
## Gregory Goyle                       2            2              2
## Draco Malfoy                        2            2              2
## Dolores Janes Umbridge              2            2              2
## Bartemius Crouch Jr.                2            2              2
## Igor Karkaroff                      3            2              2
## Percy Weasley                       1            1              1
## Fleur Delacour                      2            2              2
## Viktor Krum                         2            2              2
## Olympe Maxime                       2            2              2
## Bill Weasley                        1            1              1
## Aberforth Dumbledore                2            2              2
## Dobby                               2            2              2
## Petunia Dursley                     2            2              2
## Vernon Dursley                      2            2              2
## Nicolas Flamel                      2            2              2
## Cornelius Fudge                     1            2              2
## Rubeus Hagrid                       2            2              2
## Quirinus Quirrell                   2            2              2
## Rita Skeeter                        2            2              2
## Charlie Weasley                     1            1              1
## Dudley Dursley                      2            2              2
## Luna Lovegood                       2            2              2
## Fluffy                              2            2              2
## Aragog                              2            2              2
## Grawp                               2            2              2
## Alice Longbottom                    3            3              3
## Frank Longbottom                    3            2              2
## Xenophilius Lovegood                3            3              3
## Hedwig                              2            2              2
## Moaning Myrtle                      2            2              2
## Tom Riddle Sr.                      3            2              2
## Mary Riddle                         3            2              2
##                        Ginny Weasley Molly Weasley Ron Weasley
## Regulus Arcturus Black             2             2           2
## Sirius Black                       1             1           1
## Vincent Crabbe Sr.                 2             2           2
## Bellatrix Lestrange                2             1           1
## Lord Voldemort                     1             1           1
## Albus Dumbledore                   1             1           1
## Argus Filch                        2             2           1
## Hermione Granger                   1             1           1
## Remus Lupin                        1             2           1
## Lucius Malfoy                      2             1           1
## Narcissa Malfoy                    2             2           2
## Minerva McGonagall                 2             2           1
## Alastor Moody                      2             1           1
## Peter Pettigrew                    1             2           1
## Harry Potter                       1             1           1
## James Potter                       2             2           2
## Lily Potter                        2             2           2
## Severus Snape                      1             2           1
## Nymphadora Tonks                   2             2           2
## Arthur Weasley                     1             1           1
## Fred Weasley                       1             1           1
## George Weasley                     1             1           1
## Ginny Weasley                      0             1           1
## Molly Weasley                      1             0           1
## Ron Weasley                        1             1           0
## Lavender Brown                     2             2           1
## Seamus Finnigan                    1             2           1
## Neville Longbottom                 2             2           1
## Cho Chang                          2             2           1
## Cedric Diggory                     2             2           2
## Vincent Crabbe                     2             2           1
## Bartemius Crouch Sr.               2             2           2
## Goyle Sr.                          2             2           2
## Gregory Goyle                      2             2           1
## Draco Malfoy                       2             2           1
## Dolores Janes Umbridge             2             2           1
## Bartemius Crouch Jr.               2             2           2
## Igor Karkaroff                     2             2           2
## Percy Weasley                      1             1           1
## Fleur Delacour                     1             1           1
## Viktor Krum                        2             2           2
## Olympe Maxime                      2             2           2
## Bill Weasley                       1             1           1
## Aberforth Dumbledore               2             2           1
## Dobby                              2             2           1
## Petunia Dursley                    2             2           2
## Vernon Dursley                     2             2           2
## Nicolas Flamel                     2             2           2
## Cornelius Fudge                    2             2           2
## Rubeus Hagrid                      2             2           1
## Quirinus Quirrell                  2             2           2
## Rita Skeeter                       2             2           2
## Charlie Weasley                    1             1           1
## Dudley Dursley                     2             2           2
## Luna Lovegood                      2             2           1
## Fluffy                             2             2           1
## Aragog                             2             2           1
## Grawp                              2             2           1
## Alice Longbottom                   3             3           2
## Frank Longbottom                   2             2           2
## Xenophilius Lovegood               3             3           2
## Hedwig                             2             2           2
## Moaning Myrtle                     2             2           2
## Tom Riddle Sr.                     2             2           2
## Mary Riddle                        2             2           2
##                        Lavender Brown Seamus Finnigan Neville Longbottom
## Regulus Arcturus Black              3               3                  2
## Sirius Black                        2               2                  2
## Vincent Crabbe Sr.                  3               3                  2
## Bellatrix Lestrange                 2               2                  2
## Lord Voldemort                      2               2                  1
## Albus Dumbledore                    2               2                  2
## Argus Filch                         2               2                  2
## Hermione Granger                    1               1                  1
## Remus Lupin                         2               2                  2
## Lucius Malfoy                       2               2                  2
## Narcissa Malfoy                     3               3                  2
## Minerva McGonagall                  2               2                  2
## Alastor Moody                       2               2                  2
## Peter Pettigrew                     2               2                  2
## Harry Potter                        2               1                  1
## James Potter                        3               2                  2
## Lily Potter                         3               2                  2
## Severus Snape                       2               2                  2
## Nymphadora Tonks                    3               3                  2
## Arthur Weasley                      2               2                  2
## Fred Weasley                        2               2                  2
## George Weasley                      2               2                  2
## Ginny Weasley                       2               1                  2
## Molly Weasley                       2               2                  2
## Ron Weasley                         1               1                  1
## Lavender Brown                      0               1                  1
## Seamus Finnigan                     1               0                  1
## Neville Longbottom                  1               1                  0
## Cho Chang                           2               1                  1
## Cedric Diggory                      3               2                  2
## Vincent Crabbe                      2               2                  2
## Bartemius Crouch Sr.                3               3                  2
## Goyle Sr.                           3               3                  2
## Gregory Goyle                       2               2                  2
## Draco Malfoy                        2               2                  1
## Dolores Janes Umbridge              2               2                  2
## Bartemius Crouch Jr.                2               2                  1
## Igor Karkaroff                      3               3                  2
## Percy Weasley                       2               2                  2
## Fleur Delacour                      2               2                  1
## Viktor Krum                         2               2                  2
## Olympe Maxime                       3               3                  2
## Bill Weasley                        2               2                  2
## Aberforth Dumbledore                2               2                  2
## Dobby                               2               2                  2
## Petunia Dursley                     3               2                  2
## Vernon Dursley                      3               2                  2
## Nicolas Flamel                      3               3                  3
## Cornelius Fudge                     3               2                  2
## Rubeus Hagrid                       2               2                  1
## Quirinus Quirrell                   2               2                  2
## Rita Skeeter                        3               2                  2
## Charlie Weasley                     2               2                  2
## Dudley Dursley                      3               2                  2
## Luna Lovegood                       2               1                  1
## Fluffy                              2               2                  2
## Aragog                              2               2                  2
## Grawp                               2               2                  2
## Alice Longbottom                    2               2                  1
## Frank Longbottom                    2               2                  1
## Xenophilius Lovegood                3               2                  2
## Hedwig                              3               2                  2
## Moaning Myrtle                      3               2                  2
## Tom Riddle Sr.                      3               3                  2
## Mary Riddle                         3               3                  2
##                        Cho Chang Cedric Diggory Vincent Crabbe
## Regulus Arcturus Black         2              2              2
## Sirius Black                   2              2              2
## Vincent Crabbe Sr.             2              2              1
## Bellatrix Lestrange            2              2              2
## Lord Voldemort                 1              1              2
## Albus Dumbledore               2              2              2
## Argus Filch                    2              2              2
## Hermione Granger               1              2              1
## Remus Lupin                    2              2              2
## Lucius Malfoy                  2              2              2
## Narcissa Malfoy                2              2              2
## Minerva McGonagall             2              2              2
## Alastor Moody                  2              2              2
## Peter Pettigrew                2              2              2
## Harry Potter                   1              1              1
## James Potter                   2              2              2
## Lily Potter                    2              2              2
## Severus Snape                  2              2              2
## Nymphadora Tonks               2              2              3
## Arthur Weasley                 2              2              2
## Fred Weasley                   2              2              2
## George Weasley                 2              2              2
## Ginny Weasley                  2              2              2
## Molly Weasley                  2              2              2
## Ron Weasley                    1              2              1
## Lavender Brown                 2              3              2
## Seamus Finnigan                1              2              2
## Neville Longbottom             1              2              2
## Cho Chang                      0              1              2
## Cedric Diggory                 1              0              2
## Vincent Crabbe                 2              2              0
## Bartemius Crouch Sr.           3              3              2
## Goyle Sr.                      2              2              2
## Gregory Goyle                  2              2              1
## Draco Malfoy                   2              2              1
## Dolores Janes Umbridge         2              2              1
## Bartemius Crouch Jr.           2              2              2
## Igor Karkaroff                 2              2              3
## Percy Weasley                  2              3              2
## Fleur Delacour                 2              2              2
## Viktor Krum                    2              1              2
## Olympe Maxime                  3              3              3
## Bill Weasley                   2              2              2
## Aberforth Dumbledore           2              2              2
## Dobby                          2              2              2
## Petunia Dursley                2              2              2
## Vernon Dursley                 2              2              2
## Nicolas Flamel                 3              3              3
## Cornelius Fudge                2              2              2
## Rubeus Hagrid                  2              2              2
## Quirinus Quirrell              2              2              2
## Rita Skeeter                   2              2              2
## Charlie Weasley                2              2              2
## Dudley Dursley                 2              2              2
## Luna Lovegood                  2              2              2
## Fluffy                         2              2              2
## Aragog                         2              2              2
## Grawp                          2              2              2
## Alice Longbottom               2              3              3
## Frank Longbottom               2              2              3
## Xenophilius Lovegood           3              3              3
## Hedwig                         2              2              2
## Moaning Myrtle                 2              2              2
## Tom Riddle Sr.                 2              2              3
## Mary Riddle                    2              2              3
##                        Bartemius Crouch Sr. Goyle Sr. Gregory Goyle
## Regulus Arcturus Black                    2         2             2
## Sirius Black                              3         2             2
## Vincent Crabbe Sr.                        1         1             2
## Bellatrix Lestrange                       2         2             2
## Lord Voldemort                            2         1             1
## Albus Dumbledore                          2         2             2
## Argus Filch                               3         3             2
## Hermione Granger                          2         2             1
## Remus Lupin                               3         2             2
## Lucius Malfoy                             2         2             2
## Narcissa Malfoy                           3         2             2
## Minerva McGonagall                        2         2             2
## Alastor Moody                             2         2             2
## Peter Pettigrew                           2         2             2
## Harry Potter                              2         2             1
## James Potter                              3         2             2
## Lily Potter                               3         2             2
## Severus Snape                             2         2             2
## Nymphadora Tonks                          3         2             2
## Arthur Weasley                            2         3             2
## Fred Weasley                              2         2             2
## George Weasley                            2         2             2
## Ginny Weasley                             2         2             2
## Molly Weasley                             2         2             2
## Ron Weasley                               2         2             1
## Lavender Brown                            3         3             2
## Seamus Finnigan                           3         3             2
## Neville Longbottom                        2         2             2
## Cho Chang                                 3         2             2
## Cedric Diggory                            3         2             2
## Vincent Crabbe                            2         2             1
## Bartemius Crouch Sr.                      0         2             3
## Goyle Sr.                                 2         0             1
## Gregory Goyle                             3         1             0
## Draco Malfoy                              3         2             1
## Dolores Janes Umbridge                    3         3             2
## Bartemius Crouch Jr.                      1         2             2
## Igor Karkaroff                            1         2             2
## Percy Weasley                             1         3             2
## Fleur Delacour                            3         3             2
## Viktor Krum                               2         3             2
## Olympe Maxime                             2         3             3
## Bill Weasley                              2         2             2
## Aberforth Dumbledore                      3         3             2
## Dobby                                     3         3             2
## Petunia Dursley                           3         3             2
## Vernon Dursley                            3         3             2
## Nicolas Flamel                            3         3             3
## Cornelius Fudge                           2         3             2
## Rubeus Hagrid                             3         2             2
## Quirinus Quirrell                         3         2             2
## Rita Skeeter                              3         3             2
## Charlie Weasley                           2         2             2
## Dudley Dursley                            3         3             2
## Luna Lovegood                             3         3             2
## Fluffy                                    3         3             2
## Aragog                                    3         3             2
## Grawp                                     3         3             2
## Alice Longbottom                          3         3             3
## Frank Longbottom                          3         2             2
## Xenophilius Lovegood                      4         4             3
## Hedwig                                    3         3             2
## Moaning Myrtle                            3         3             2
## Tom Riddle Sr.                            3         2             2
## Mary Riddle                               3         2             2
##                        Draco Malfoy Dolores Janes Umbridge
## Regulus Arcturus Black            3                      3
## Sirius Black                      2                      2
## Vincent Crabbe Sr.                2                      2
## Bellatrix Lestrange               2                      2
## Lord Voldemort                    2                      2
## Albus Dumbledore                  2                      1
## Argus Filch                       2                      1
## Hermione Granger                  1                      1
## Remus Lupin                       2                      2
## Lucius Malfoy                     1                      2
## Narcissa Malfoy                   1                      3
## Minerva McGonagall                2                      1
## Alastor Moody                     2                      2
## Peter Pettigrew                   2                      2
## Harry Potter                      1                      1
## James Potter                      2                      2
## Lily Potter                       2                      2
## Severus Snape                     2                      2
## Nymphadora Tonks                  3                      3
## Arthur Weasley                    2                      2
## Fred Weasley                      2                      2
## George Weasley                    2                      2
## Ginny Weasley                     2                      2
## Molly Weasley                     2                      2
## Ron Weasley                       1                      1
## Lavender Brown                    2                      2
## Seamus Finnigan                   2                      2
## Neville Longbottom                1                      2
## Cho Chang                         2                      2
## Cedric Diggory                    2                      2
## Vincent Crabbe                    1                      1
## Bartemius Crouch Sr.              3                      3
## Goyle Sr.                         2                      3
## Gregory Goyle                     1                      2
## Draco Malfoy                      0                      2
## Dolores Janes Umbridge            2                      0
## Bartemius Crouch Jr.              2                      2
## Igor Karkaroff                    3                      3
## Percy Weasley                     2                      2
## Fleur Delacour                    2                      2
## Viktor Krum                       2                      2
## Olympe Maxime                     3                      2
## Bill Weasley                      2                      2
## Aberforth Dumbledore              2                      2
## Dobby                             1                      2
## Petunia Dursley                   2                      2
## Vernon Dursley                    2                      2
## Nicolas Flamel                    3                      2
## Cornelius Fudge                   2                      1
## Rubeus Hagrid                     2                      2
## Quirinus Quirrell                 2                      2
## Rita Skeeter                      2                      2
## Charlie Weasley                   2                      2
## Dudley Dursley                    2                      2
## Luna Lovegood                     2                      2
## Fluffy                            2                      2
## Aragog                            2                      2
## Grawp                             2                      2
## Alice Longbottom                  2                      3
## Frank Longbottom                  2                      3
## Xenophilius Lovegood              3                      3
## Hedwig                            2                      2
## Moaning Myrtle                    2                      2
## Tom Riddle Sr.                    3                      3
## Mary Riddle                       3                      3
##                        Bartemius Crouch Jr. Igor Karkaroff Percy Weasley
## Regulus Arcturus Black                    2              2             3
## Sirius Black                              2              2             2
## Vincent Crabbe Sr.                        2              2             2
## Bellatrix Lestrange                       2              2             2
## Lord Voldemort                            1              1             2
## Albus Dumbledore                          2              2             1
## Argus Filch                               2              3             2
## Hermione Granger                          1              2             2
## Remus Lupin                               2              2             2
## Lucius Malfoy                             2              2             2
## Narcissa Malfoy                           2              2             3
## Minerva McGonagall                        1              2             2
## Alastor Moody                             1              2             2
## Peter Pettigrew                           1              2             2
## Harry Potter                              1              2             2
## James Potter                              2              2             2
## Lily Potter                               2              2             2
## Severus Snape                             1              2             2
## Nymphadora Tonks                          2              2             3
## Arthur Weasley                            2              3             1
## Fred Weasley                              2              2             1
## George Weasley                            2              2             1
## Ginny Weasley                             2              2             1
## Molly Weasley                             2              2             1
## Ron Weasley                               2              2             1
## Lavender Brown                            2              3             2
## Seamus Finnigan                           2              3             2
## Neville Longbottom                        1              2             2
## Cho Chang                                 2              2             2
## Cedric Diggory                            2              2             3
## Vincent Crabbe                            2              3             2
## Bartemius Crouch Sr.                      1              1             1
## Goyle Sr.                                 2              2             3
## Gregory Goyle                             2              2             2
## Draco Malfoy                              2              3             2
## Dolores Janes Umbridge                    2              3             2
## Bartemius Crouch Jr.                      0              2             2
## Igor Karkaroff                            2              0             2
## Percy Weasley                             2              2             0
## Fleur Delacour                            2              2             2
## Viktor Krum                               2              1             3
## Olympe Maxime                             3              1             2
## Bill Weasley                              2              2             1
## Aberforth Dumbledore                      2              3             2
## Dobby                                     2              3             2
## Petunia Dursley                           2              3             2
## Vernon Dursley                            2              3             2
## Nicolas Flamel                            3              3             2
## Cornelius Fudge                           2              3             1
## Rubeus Hagrid                             2              2             2
## Quirinus Quirrell                         2              2             2
## Rita Skeeter                              2              3             2
## Charlie Weasley                           2              2             1
## Dudley Dursley                            2              3             3
## Luna Lovegood                             2              3             2
## Fluffy                                    2              3             2
## Aragog                                    2              3             2
## Grawp                                     2              3             2
## Alice Longbottom                          2              3             3
## Frank Longbottom                          2              2             3
## Xenophilius Lovegood                      3              4             3
## Hedwig                                    2              3             3
## Moaning Myrtle                            2              3             3
## Tom Riddle Sr.                            2              2             3
## Mary Riddle                               2              2             3
##                        Fleur Delacour Viktor Krum Olympe Maxime
## Regulus Arcturus Black              2           3             3
## Sirius Black                        2           2             2
## Vincent Crabbe Sr.                  2           3             3
## Bellatrix Lestrange                 1           2             2
## Lord Voldemort                      2           2             2
## Albus Dumbledore                    2           2             1
## Argus Filch                         2           2             2
## Hermione Granger                    1           1             2
## Remus Lupin                         2           2             2
## Lucius Malfoy                       2           2             3
## Narcissa Malfoy                     2           3             3
## Minerva McGonagall                  2           2             2
## Alastor Moody                       1           2             2
## Peter Pettigrew                     2           2             2
## Harry Potter                        1           1             2
## James Potter                        2           2             2
## Lily Potter                         2           2             2
## Severus Snape                       2           2             2
## Nymphadora Tonks                    2           3             3
## Arthur Weasley                      2           2             2
## Fred Weasley                        2           2             2
## George Weasley                      2           2             2
## Ginny Weasley                       1           2             2
## Molly Weasley                       1           2             2
## Ron Weasley                         1           2             2
## Lavender Brown                      2           2             3
## Seamus Finnigan                     2           2             3
## Neville Longbottom                  1           2             2
## Cho Chang                           2           2             3
## Cedric Diggory                      2           1             3
## Vincent Crabbe                      2           2             3
## Bartemius Crouch Sr.                3           2             2
## Goyle Sr.                           3           3             3
## Gregory Goyle                       2           2             3
## Draco Malfoy                        2           2             3
## Dolores Janes Umbridge              2           2             2
## Bartemius Crouch Jr.                2           2             3
## Igor Karkaroff                      2           1             1
## Percy Weasley                       2           3             2
## Fleur Delacour                      0           1             1
## Viktor Krum                         1           0             2
## Olympe Maxime                       1           2             0
## Bill Weasley                        1           2             2
## Aberforth Dumbledore                2           2             2
## Dobby                               2           2             3
## Petunia Dursley                     2           2             2
## Vernon Dursley                      2           2             2
## Nicolas Flamel                      3           3             2
## Cornelius Fudge                     2           2             2
## Rubeus Hagrid                       2           2             1
## Quirinus Quirrell                   2           2             2
## Rita Skeeter                        2           2             2
## Charlie Weasley                     2           2             2
## Dudley Dursley                      2           2             2
## Luna Lovegood                       2           2             3
## Fluffy                              2           2             2
## Aragog                              2           2             2
## Grawp                               2           2             2
## Alice Longbottom                    2           3             3
## Frank Longbottom                    2           3             3
## Xenophilius Lovegood                3           3             4
## Hedwig                              2           2             3
## Moaning Myrtle                      2           2             3
## Tom Riddle Sr.                      3           3             3
## Mary Riddle                         3           3             3
##                        Bill Weasley Aberforth Dumbledore Dobby
## Regulus Arcturus Black            2                    3     2
## Sirius Black                      2                    2     2
## Vincent Crabbe Sr.                2                    3     2
## Bellatrix Lestrange               2                    2     1
## Lord Voldemort                    1                    2     2
## Albus Dumbledore                  1                    1     2
## Argus Filch                       2                    2     2
## Hermione Granger                  1                    1     1
## Remus Lupin                       2                    2     2
## Lucius Malfoy                     2                    2     1
## Narcissa Malfoy                   2                    3     2
## Minerva McGonagall                2                    2     2
## Alastor Moody                     2                    2     2
## Peter Pettigrew                   2                    2     2
## Harry Potter                      1                    1     1
## James Potter                      2                    2     2
## Lily Potter                       2                    2     2
## Severus Snape                     2                    2     2
## Nymphadora Tonks                  2                    3     2
## Arthur Weasley                    1                    2     2
## Fred Weasley                      1                    2     2
## George Weasley                    1                    2     2
## Ginny Weasley                     1                    2     2
## Molly Weasley                     1                    2     2
## Ron Weasley                       1                    1     1
## Lavender Brown                    2                    2     2
## Seamus Finnigan                   2                    2     2
## Neville Longbottom                2                    2     2
## Cho Chang                         2                    2     2
## Cedric Diggory                    2                    2     2
## Vincent Crabbe                    2                    2     2
## Bartemius Crouch Sr.              2                    3     3
## Goyle Sr.                         2                    3     3
## Gregory Goyle                     2                    2     2
## Draco Malfoy                      2                    2     1
## Dolores Janes Umbridge            2                    2     2
## Bartemius Crouch Jr.              2                    2     2
## Igor Karkaroff                    2                    3     3
## Percy Weasley                     1                    2     2
## Fleur Delacour                    1                    2     2
## Viktor Krum                       2                    2     2
## Olympe Maxime                     2                    2     3
## Bill Weasley                      0                    2     2
## Aberforth Dumbledore              2                    0     1
## Dobby                             2                    1     0
## Petunia Dursley                   2                    2     2
## Vernon Dursley                    2                    2     2
## Nicolas Flamel                    2                    2     3
## Cornelius Fudge                   2                    2     2
## Rubeus Hagrid                     2                    2     2
## Quirinus Quirrell                 2                    2     2
## Rita Skeeter                      2                    2     2
## Charlie Weasley                   1                    2     2
## Dudley Dursley                    2                    2     2
## Luna Lovegood                     2                    2     2
## Fluffy                            2                    2     2
## Aragog                            2                    2     2
## Grawp                             2                    2     2
## Alice Longbottom                  3                    3     3
## Frank Longbottom                  2                    3     3
## Xenophilius Lovegood              3                    3     3
## Hedwig                            2                    2     2
## Moaning Myrtle                    2                    2     2
## Tom Riddle Sr.                    2                    3     3
## Mary Riddle                       2                    3     3
##                        Petunia Dursley Vernon Dursley Nicolas Flamel
## Regulus Arcturus Black               3              3              3
## Sirius Black                         2              2              2
## Vincent Crabbe Sr.                   3              3              3
## Bellatrix Lestrange                  2              2              2
## Lord Voldemort                       2              2              2
## Albus Dumbledore                     1              1              1
## Argus Filch                          2              2              2
## Hermione Granger                     2              2              2
## Remus Lupin                          2              2              2
## Lucius Malfoy                        2              2              3
## Narcissa Malfoy                      3              3              3
## Minerva McGonagall                   2              2              2
## Alastor Moody                        2              2              2
## Peter Pettigrew                      2              2              2
## Harry Potter                         1              1              2
## James Potter                         2              2              2
## Lily Potter                          1              2              2
## Severus Snape                        2              2              2
## Nymphadora Tonks                     3              3              3
## Arthur Weasley                       2              2              2
## Fred Weasley                         2              2              2
## George Weasley                       2              2              2
## Ginny Weasley                        2              2              2
## Molly Weasley                        2              2              2
## Ron Weasley                          2              2              2
## Lavender Brown                       3              3              3
## Seamus Finnigan                      2              2              3
## Neville Longbottom                   2              2              3
## Cho Chang                            2              2              3
## Cedric Diggory                       2              2              3
## Vincent Crabbe                       2              2              3
## Bartemius Crouch Sr.                 3              3              3
## Goyle Sr.                            3              3              3
## Gregory Goyle                        2              2              3
## Draco Malfoy                         2              2              3
## Dolores Janes Umbridge               2              2              2
## Bartemius Crouch Jr.                 2              2              3
## Igor Karkaroff                       3              3              3
## Percy Weasley                        2              2              2
## Fleur Delacour                       2              2              3
## Viktor Krum                          2              2              3
## Olympe Maxime                        2              2              2
## Bill Weasley                         2              2              2
## Aberforth Dumbledore                 2              2              2
## Dobby                                2              2              3
## Petunia Dursley                      0              1              2
## Vernon Dursley                       1              0              2
## Nicolas Flamel                       2              2              0
## Cornelius Fudge                      2              2              2
## Rubeus Hagrid                        2              2              2
## Quirinus Quirrell                    2              2              2
## Rita Skeeter                         2              2              2
## Charlie Weasley                      2              2              2
## Dudley Dursley                       1              1              3
## Luna Lovegood                        2              2              3
## Fluffy                               2              2              3
## Aragog                               2              2              3
## Grawp                                2              2              3
## Alice Longbottom                     3              3              4
## Frank Longbottom                     3              3              3
## Xenophilius Lovegood                 3              3              4
## Hedwig                               2              2              3
## Moaning Myrtle                       2              2              3
## Tom Riddle Sr.                       3              3              3
## Mary Riddle                          3              3              3
##                        Cornelius Fudge Rubeus Hagrid Quirinus Quirrell
## Regulus Arcturus Black               3             2                 2
## Sirius Black                         2             2                 2
## Vincent Crabbe Sr.                   2             2                 2
## Bellatrix Lestrange                  2             2                 2
## Lord Voldemort                       2             1                 1
## Albus Dumbledore                     1             1                 1
## Argus Filch                          2             1                 2
## Hermione Granger                     2             1                 1
## Remus Lupin                          2             2                 2
## Lucius Malfoy                        1             2                 2
## Narcissa Malfoy                      2             2                 2
## Minerva McGonagall                   2             1                 2
## Alastor Moody                        2             2                 2
## Peter Pettigrew                      2             2                 2
## Harry Potter                         1             1                 1
## James Potter                         2             2                 2
## Lily Potter                          2             2                 2
## Severus Snape                        2             1                 2
## Nymphadora Tonks                     3             2                 2
## Arthur Weasley                       1             2                 2
## Fred Weasley                         2             2                 2
## George Weasley                       2             2                 2
## Ginny Weasley                        2             2                 2
## Molly Weasley                        2             2                 2
## Ron Weasley                          2             1                 2
## Lavender Brown                       3             2                 2
## Seamus Finnigan                      2             2                 2
## Neville Longbottom                   2             1                 2
## Cho Chang                            2             2                 2
## Cedric Diggory                       2             2                 2
## Vincent Crabbe                       2             2                 2
## Bartemius Crouch Sr.                 2             3                 3
## Goyle Sr.                            3             2                 2
## Gregory Goyle                        2             2                 2
## Draco Malfoy                         2             2                 2
## Dolores Janes Umbridge               1             2                 2
## Bartemius Crouch Jr.                 2             2                 2
## Igor Karkaroff                       3             2                 2
## Percy Weasley                        1             2                 2
## Fleur Delacour                       2             2                 2
## Viktor Krum                          2             2                 2
## Olympe Maxime                        2             1                 2
## Bill Weasley                         2             2                 2
## Aberforth Dumbledore                 2             2                 2
## Dobby                                2             2                 2
## Petunia Dursley                      2             2                 2
## Vernon Dursley                       2             2                 2
## Nicolas Flamel                       2             2                 2
## Cornelius Fudge                      0             2                 2
## Rubeus Hagrid                        2             0                 2
## Quirinus Quirrell                    2             2                 0
## Rita Skeeter                         2             2                 2
## Charlie Weasley                      2             2                 2
## Dudley Dursley                       2             1                 2
## Luna Lovegood                        2             2                 2
## Fluffy                               2             1                 2
## Aragog                               2             1                 2
## Grawp                                2             1                 2
## Alice Longbottom                     3             2                 3
## Frank Longbottom                     3             2                 2
## Xenophilius Lovegood                 3             3                 3
## Hedwig                               2             2                 2
## Moaning Myrtle                       2             2                 2
## Tom Riddle Sr.                       3             2                 2
## Mary Riddle                          3             2                 2
##                        Rita Skeeter Charlie Weasley Dudley Dursley
## Regulus Arcturus Black            3               2              3
## Sirius Black                      2               2              2
## Vincent Crabbe Sr.                3               2              3
## Bellatrix Lestrange               2               2              2
## Lord Voldemort                    2               1              2
## Albus Dumbledore                  1               1              2
## Argus Filch                       2               2              2
## Hermione Granger                  2               1              2
## Remus Lupin                       2               2              2
## Lucius Malfoy                     2               2              2
## Narcissa Malfoy                   3               2              3
## Minerva McGonagall                2               2              2
## Alastor Moody                     2               2              2
## Peter Pettigrew                   2               2              2
## Harry Potter                      1               1              1
## James Potter                      2               2              2
## Lily Potter                       2               2              2
## Severus Snape                     2               2              2
## Nymphadora Tonks                  3               2              3
## Arthur Weasley                    2               1              2
## Fred Weasley                      2               1              2
## George Weasley                    2               1              2
## Ginny Weasley                     2               1              2
## Molly Weasley                     2               1              2
## Ron Weasley                       2               1              2
## Lavender Brown                    3               2              3
## Seamus Finnigan                   2               2              2
## Neville Longbottom                2               2              2
## Cho Chang                         2               2              2
## Cedric Diggory                    2               2              2
## Vincent Crabbe                    2               2              2
## Bartemius Crouch Sr.              3               2              3
## Goyle Sr.                         3               2              3
## Gregory Goyle                     2               2              2
## Draco Malfoy                      2               2              2
## Dolores Janes Umbridge            2               2              2
## Bartemius Crouch Jr.              2               2              2
## Igor Karkaroff                    3               2              3
## Percy Weasley                     2               1              3
## Fleur Delacour                    2               2              2
## Viktor Krum                       2               2              2
## Olympe Maxime                     2               2              2
## Bill Weasley                      2               1              2
## Aberforth Dumbledore              2               2              2
## Dobby                             2               2              2
## Petunia Dursley                   2               2              1
## Vernon Dursley                    2               2              1
## Nicolas Flamel                    2               2              3
## Cornelius Fudge                   2               2              2
## Rubeus Hagrid                     2               2              1
## Quirinus Quirrell                 2               2              2
## Rita Skeeter                      0               2              2
## Charlie Weasley                   2               0              2
## Dudley Dursley                    2               2              0
## Luna Lovegood                     2               2              2
## Fluffy                            2               2              2
## Aragog                            2               2              2
## Grawp                             2               2              2
## Alice Longbottom                  3               3              3
## Frank Longbottom                  3               2              3
## Xenophilius Lovegood              3               3              3
## Hedwig                            2               2              2
## Moaning Myrtle                    2               2              2
## Tom Riddle Sr.                    3               2              3
## Mary Riddle                       3               2              3
##                        Luna Lovegood Fluffy Aragog Grawp Alice Longbottom
## Regulus Arcturus Black             3      3      3     3                3
## Sirius Black                       2      2      2     2                3
## Vincent Crabbe Sr.                 3      3      3     3                3
## Bellatrix Lestrange                2      2      2     2                3
## Lord Voldemort                     2      2      2     2                2
## Albus Dumbledore                   2      2      2     2                3
## Argus Filch                        2      2      2     2                3
## Hermione Granger                   1      1      1     1                2
## Remus Lupin                        2      2      2     2                3
## Lucius Malfoy                      2      2      2     2                3
## Narcissa Malfoy                    3      3      3     3                3
## Minerva McGonagall                 2      2      2     2                3
## Alastor Moody                      2      2      2     2                3
## Peter Pettigrew                    2      2      2     2                3
## Harry Potter                       1      1      1     1                2
## James Potter                       2      2      2     2                3
## Lily Potter                        2      2      2     2                3
## Severus Snape                      2      2      2     2                3
## Nymphadora Tonks                   3      3      3     3                3
## Arthur Weasley                     2      2      2     2                3
## Fred Weasley                       2      2      2     2                3
## George Weasley                     2      2      2     2                3
## Ginny Weasley                      2      2      2     2                3
## Molly Weasley                      2      2      2     2                3
## Ron Weasley                        1      1      1     1                2
## Lavender Brown                     2      2      2     2                2
## Seamus Finnigan                    1      2      2     2                2
## Neville Longbottom                 1      2      2     2                1
## Cho Chang                          2      2      2     2                2
## Cedric Diggory                     2      2      2     2                3
## Vincent Crabbe                     2      2      2     2                3
## Bartemius Crouch Sr.               3      3      3     3                3
## Goyle Sr.                          3      3      3     3                3
## Gregory Goyle                      2      2      2     2                3
## Draco Malfoy                       2      2      2     2                2
## Dolores Janes Umbridge             2      2      2     2                3
## Bartemius Crouch Jr.               2      2      2     2                2
## Igor Karkaroff                     3      3      3     3                3
## Percy Weasley                      2      2      2     2                3
## Fleur Delacour                     2      2      2     2                2
## Viktor Krum                        2      2      2     2                3
## Olympe Maxime                      3      2      2     2                3
## Bill Weasley                       2      2      2     2                3
## Aberforth Dumbledore               2      2      2     2                3
## Dobby                              2      2      2     2                3
## Petunia Dursley                    2      2      2     2                3
## Vernon Dursley                     2      2      2     2                3
## Nicolas Flamel                     3      3      3     3                4
## Cornelius Fudge                    2      2      2     2                3
## Rubeus Hagrid                      2      1      1     1                2
## Quirinus Quirrell                  2      2      2     2                3
## Rita Skeeter                       2      2      2     2                3
## Charlie Weasley                    2      2      2     2                3
## Dudley Dursley                     2      2      2     2                3
## Luna Lovegood                      0      2      2     2                2
## Fluffy                             2      0      2     2                3
## Aragog                             2      2      0     2                3
## Grawp                              2      2      2     0                3
## Alice Longbottom                   2      3      3     3                0
## Frank Longbottom                   2      3      3     3                1
## Xenophilius Lovegood               1      3      3     3                3
## Hedwig                             2      2      2     2                3
## Moaning Myrtle                     2      2      2     2                3
## Tom Riddle Sr.                     3      3      3     3                3
## Mary Riddle                        3      3      3     3                3
##                        Frank Longbottom Xenophilius Lovegood Hedwig
## Regulus Arcturus Black                2                    4      3
## Sirius Black                          2                    3      2
## Vincent Crabbe Sr.                    2                    4      3
## Bellatrix Lestrange                   2                    3      2
## Lord Voldemort                        1                    3      2
## Albus Dumbledore                      2                    3      2
## Argus Filch                           3                    3      2
## Hermione Granger                      2                    2      2
## Remus Lupin                           2                    3      2
## Lucius Malfoy                         2                    3      2
## Narcissa Malfoy                       2                    4      3
## Minerva McGonagall                    2                    3      2
## Alastor Moody                         2                    3      2
## Peter Pettigrew                       2                    3      2
## Harry Potter                          2                    2      1
## James Potter                          2                    3      2
## Lily Potter                           2                    3      2
## Severus Snape                         2                    3      2
## Nymphadora Tonks                      2                    4      3
## Arthur Weasley                        3                    3      2
## Fred Weasley                          2                    3      2
## George Weasley                        2                    3      2
## Ginny Weasley                         2                    3      2
## Molly Weasley                         2                    3      2
## Ron Weasley                           2                    2      2
## Lavender Brown                        2                    3      3
## Seamus Finnigan                       2                    2      2
## Neville Longbottom                    1                    2      2
## Cho Chang                             2                    3      2
## Cedric Diggory                        2                    3      2
## Vincent Crabbe                        3                    3      2
## Bartemius Crouch Sr.                  3                    4      3
## Goyle Sr.                             2                    4      3
## Gregory Goyle                         2                    3      2
## Draco Malfoy                          2                    3      2
## Dolores Janes Umbridge                3                    3      2
## Bartemius Crouch Jr.                  2                    3      2
## Igor Karkaroff                        2                    4      3
## Percy Weasley                         3                    3      3
## Fleur Delacour                        2                    3      2
## Viktor Krum                           3                    3      2
## Olympe Maxime                         3                    4      3
## Bill Weasley                          2                    3      2
## Aberforth Dumbledore                  3                    3      2
## Dobby                                 3                    3      2
## Petunia Dursley                       3                    3      2
## Vernon Dursley                        3                    3      2
## Nicolas Flamel                        3                    4      3
## Cornelius Fudge                       3                    3      2
## Rubeus Hagrid                         2                    3      2
## Quirinus Quirrell                     2                    3      2
## Rita Skeeter                          3                    3      2
## Charlie Weasley                       2                    3      2
## Dudley Dursley                        3                    3      2
## Luna Lovegood                         2                    1      2
## Fluffy                                3                    3      2
## Aragog                                3                    3      2
## Grawp                                 3                    3      2
## Alice Longbottom                      1                    3      3
## Frank Longbottom                      0                    3      3
## Xenophilius Lovegood                  3                    0      3
## Hedwig                                3                    3      0
## Moaning Myrtle                        3                    3      2
## Tom Riddle Sr.                        2                    4      3
## Mary Riddle                           2                    4      3
##                        Moaning Myrtle Tom Riddle Sr. Mary Riddle
## Regulus Arcturus Black              3              2           2
## Sirius Black                        2              2           2
## Vincent Crabbe Sr.                  3              2           2
## Bellatrix Lestrange                 2              2           2
## Lord Voldemort                      2              1           1
## Albus Dumbledore                    2              2           2
## Argus Filch                         2              3           3
## Hermione Granger                    2              2           2
## Remus Lupin                         2              2           2
## Lucius Malfoy                       2              2           2
## Narcissa Malfoy                     3              2           2
## Minerva McGonagall                  2              2           2
## Alastor Moody                       2              2           2
## Peter Pettigrew                     2              2           2
## Harry Potter                        1              2           2
## James Potter                        2              2           2
## Lily Potter                         2              2           2
## Severus Snape                       2              2           2
## Nymphadora Tonks                    3              2           2
## Arthur Weasley                      2              3           3
## Fred Weasley                        2              2           2
## George Weasley                      2              2           2
## Ginny Weasley                       2              2           2
## Molly Weasley                       2              2           2
## Ron Weasley                         2              2           2
## Lavender Brown                      3              3           3
## Seamus Finnigan                     2              3           3
## Neville Longbottom                  2              2           2
## Cho Chang                           2              2           2
## Cedric Diggory                      2              2           2
## Vincent Crabbe                      2              3           3
## Bartemius Crouch Sr.                3              3           3
## Goyle Sr.                           3              2           2
## Gregory Goyle                       2              2           2
## Draco Malfoy                        2              3           3
## Dolores Janes Umbridge              2              3           3
## Bartemius Crouch Jr.                2              2           2
## Igor Karkaroff                      3              2           2
## Percy Weasley                       3              3           3
## Fleur Delacour                      2              3           3
## Viktor Krum                         2              3           3
## Olympe Maxime                       3              3           3
## Bill Weasley                        2              2           2
## Aberforth Dumbledore                2              3           3
## Dobby                               2              3           3
## Petunia Dursley                     2              3           3
## Vernon Dursley                      2              3           3
## Nicolas Flamel                      3              3           3
## Cornelius Fudge                     2              3           3
## Rubeus Hagrid                       2              2           2
## Quirinus Quirrell                   2              2           2
## Rita Skeeter                        2              3           3
## Charlie Weasley                     2              2           2
## Dudley Dursley                      2              3           3
## Luna Lovegood                       2              3           3
## Fluffy                              2              3           3
## Aragog                              2              3           3
## Grawp                               2              3           3
## Alice Longbottom                    3              3           3
## Frank Longbottom                    3              2           2
## Xenophilius Lovegood                3              4           4
## Hedwig                              2              3           3
## Moaning Myrtle                      0              3           3
## Tom Riddle Sr.                      3              0           1
## Mary Riddle                         3              1           0

Network Diameter

In contrast to the shortest path between two nodes, we can also calculate the longest path, or diameter. The network diameter describes the longest possible distance between two vertices in terms of the most efficient path.

In our network, the longest path connects 4 edges (5 characters).

get_diameter returns a path with the actual diameter. In our case, the diameter passes by: Regulus Arcturus Black, Sirius Black, Hermione Granger, Luna Lovegood and Xenophilius Lovegood. From this result, we can assume that some of these characters have high centrality measures (to confirm below).

diameter_characters<-diameter(g11, directed=F)
diameter_characters #length of diameter
## [1] 4
get_diameter(g11) #list of characters that are part of the diameter
## + 5/65 vertices, named, from 861146a:
## [1] Regulus Arcturus Black Sirius Black           Hermione Granger      
## [4] Luna Lovegood          Xenophilius Lovegood

Plotting Longest Path in Harry Potter Network

The following graph plots the whole network but highlights the diameter in red. Surprisingly, the diameter goes through Hermione Granger, instead of Harry Potter. Harry Potter seems to be able to make the same connections as Hermione Granger, but wasn’t chosen, most likely, because he has a smaller level of degree (discussed later).

par(mar=c(1,1,3,1)) #layout of the RMarkdown

g11_diameter <- g11
node_diameter <- get.diameter(g11_diameter,  directed = FALSE) #assignment the diameter parth to the igraph

#Specifying the nodes' and edge's characteristics (color, size, transparency, width)
V(g11_diameter)$color <- scales::alpha(V(g11_diameter)$color, alpha = 4)
## Warning in length(vattrs[[name]]) <- vc: length of NULL cannot be changed
V(g11_diameter)$size <- 10

V(g11_diameter)[node_diameter]$color <- "red"
V(g11_diameter)[node_diameter]$size <- 20

E(g11_diameter)$color <- "grey"
E(g11_diameter)$width <- 0.01

E(g11_diameter, path = node_diameter)$color <- "red"
E(g11_diameter, path = node_diameter)$width <- 3

#Plotting the whole graph
plot(g11_diameter,
     layout = mylayout,
     legend = TRUE,
     vertex.label = V(g11_diameter)$Character,
     vertex.frame.color = "gray", 
     vertex.label.color = "black", 
     vertex.label.cex = 0.6,
     vertex.label.dist=3,
     edge.lty = E(g11_diameter)$lty,
     asp = 0.75,
     rescale = FALSE,
     ylim = c(-4.5,4),
     xlim = c(-5,2))
legend("topleft", legend = "", cex = 1.25, bty = "n", ncol = 1,
       title = "The Network's Diameter")

Giant Component

In most of the research topics for network analysis, network features are related to the largest connected component of a graph (Newman 2010). In order to get that for an igraph or a network object, giant_component_extract function is specified. This function extracts the strongest components of the input network as igraph objects.

In the end, for this network, the function only gives us 2 lists of the edges. This may be a consequence of a small node network, where all the edges are strong compenents (due to the limited size of the network).

giant_component_extract(g11)
## [[1]]
## IGRAPH 871171d UN-- 65 330 -- 
## + attr: name (v/c), Alignment (v/c), Gender_Male (v/n), House
## | (v/c), Color (v/c)
## + edges from 871171d (vertex names):
##  [1] Regulus Arcturus Black--Sirius Black       
##  [2] Regulus Arcturus Black--Vincent Crabbe Sr. 
##  [3] Regulus Arcturus Black--Bellatrix Lestrange
##  [4] Regulus Arcturus Black--Lord Voldemort     
##  [5] Sirius Black          --Albus Dumbledore   
##  [6] Sirius Black          --Argus Filch        
##  [7] Sirius Black          --Hermione Granger   
## + ... omitted several edges
## 
## [[2]]
##        [,1]                     [,2]                    
##   [1,] "Regulus Arcturus Black" "Sirius Black"          
##   [2,] "Regulus Arcturus Black" "Vincent Crabbe Sr."    
##   [3,] "Regulus Arcturus Black" "Bellatrix Lestrange"   
##   [4,] "Regulus Arcturus Black" "Lord Voldemort"        
##   [5,] "Sirius Black"           "Albus Dumbledore"      
##   [6,] "Sirius Black"           "Argus Filch"           
##   [7,] "Sirius Black"           "Hermione Granger"      
##   [8,] "Sirius Black"           "Bellatrix Lestrange"   
##   [9,] "Sirius Black"           "Remus Lupin"           
##  [10,] "Sirius Black"           "Lucius Malfoy"         
##  [11,] "Sirius Black"           "Narcissa Malfoy"       
##  [12,] "Sirius Black"           "Minerva McGonagall"    
##  [13,] "Sirius Black"           "Alastor Moody"         
##  [14,] "Sirius Black"           "Peter Pettigrew"       
##  [15,] "Sirius Black"           "Harry Potter"          
##  [16,] "Sirius Black"           "James Potter"          
##  [17,] "Sirius Black"           "Lily Potter"           
##  [18,] "Sirius Black"           "Lord Voldemort"        
##  [19,] "Sirius Black"           "Severus Snape"         
##  [20,] "Sirius Black"           "Nymphadora Tonks"      
##  [21,] "Sirius Black"           "Arthur Weasley"        
##  [22,] "Sirius Black"           "Fred Weasley"          
##  [23,] "Sirius Black"           "George Weasley"        
##  [24,] "Sirius Black"           "Ginny Weasley"         
##  [25,] "Sirius Black"           "Molly Weasley"         
##  [26,] "Sirius Black"           "Ron Weasley"           
##  [27,] "Lavender Brown"         "Seamus Finnigan"       
##  [28,] "Lavender Brown"         "Hermione Granger"      
##  [29,] "Lavender Brown"         "Neville Longbottom"    
##  [30,] "Lavender Brown"         "Ron Weasley"           
##  [31,] "Cho Chang"              "Cedric Diggory"        
##  [32,] "Cho Chang"              "Seamus Finnigan"       
##  [33,] "Cho Chang"              "Hermione Granger"      
##  [34,] "Cho Chang"              "Neville Longbottom"    
##  [35,] "Cho Chang"              "Harry Potter"          
##  [36,] "Cho Chang"              "Lord Voldemort"        
##  [37,] "Cho Chang"              "Ron Weasley"           
##  [38,] "Vincent Crabbe Sr."     "Vincent Crabbe"        
##  [39,] "Vincent Crabbe Sr."     "Bartemius Crouch Sr."  
##  [40,] "Vincent Crabbe Sr."     "Goyle Sr."             
##  [41,] "Vincent Crabbe Sr."     "Bellatrix Lestrange"   
##  [42,] "Vincent Crabbe Sr."     "Lucius Malfoy"         
##  [43,] "Vincent Crabbe Sr."     "Peter Pettigrew"       
##  [44,] "Vincent Crabbe Sr."     "Lord Voldemort"        
##  [45,] "Vincent Crabbe Sr."     "Severus Snape"         
##  [46,] "Vincent Crabbe"         "Gregory Goyle"         
##  [47,] "Vincent Crabbe"         "Hermione Granger"      
##  [48,] "Vincent Crabbe"         "Draco Malfoy"          
##  [49,] "Vincent Crabbe"         "Harry Potter"          
##  [50,] "Vincent Crabbe"         "Dolores Janes Umbridge"
##  [51,] "Vincent Crabbe"         "Ron Weasley"           
##  [52,] "Bartemius Crouch Sr."   "Bartemius Crouch Jr."  
##  [53,] "Bartemius Crouch Sr."   "Igor Karkaroff"        
##  [54,] "Bartemius Crouch Sr."   "Percy Weasley"         
##  [55,] "Bartemius Crouch Jr."   "Hermione Granger"      
##  [56,] "Bartemius Crouch Jr."   "Neville Longbottom"    
##  [57,] "Bartemius Crouch Jr."   "Minerva McGonagall"    
##  [58,] "Bartemius Crouch Jr."   "Alastor Moody"         
##  [59,] "Bartemius Crouch Jr."   "Peter Pettigrew"       
##  [60,] "Bartemius Crouch Jr."   "Harry Potter"          
##  [61,] "Bartemius Crouch Jr."   "Lord Voldemort"        
##  [62,] "Bartemius Crouch Jr."   "Severus Snape"         
##  [63,] "Fleur Delacour"         "Hermione Granger"      
##  [64,] "Fleur Delacour"         "Viktor Krum"           
##  [65,] "Fleur Delacour"         "Bellatrix Lestrange"   
##  [66,] "Fleur Delacour"         "Neville Longbottom"    
##  [67,] "Fleur Delacour"         "Olympe Maxime"         
##  [68,] "Fleur Delacour"         "Alastor Moody"         
##  [69,] "Fleur Delacour"         "Harry Potter"          
##  [70,] "Fleur Delacour"         "Bill Weasley"          
##  [71,] "Fleur Delacour"         "Ginny Weasley"         
##  [72,] "Fleur Delacour"         "Molly Weasley"         
##  [73,] "Fleur Delacour"         "Ron Weasley"           
##  [74,] "Cedric Diggory"         "Viktor Krum"           
##  [75,] "Cedric Diggory"         "Harry Potter"          
##  [76,] "Cedric Diggory"         "Lord Voldemort"        
##  [77,] "Aberforth Dumbledore"   "Albus Dumbledore"      
##  [78,] "Aberforth Dumbledore"   "Hermione Granger"      
##  [79,] "Aberforth Dumbledore"   "Harry Potter"          
##  [80,] "Aberforth Dumbledore"   "Ron Weasley"           
##  [81,] "Aberforth Dumbledore"   "Dobby"                 
##  [82,] "Albus Dumbledore"       "Petunia Dursley"       
##  [83,] "Albus Dumbledore"       "Vernon Dursley"        
##  [84,] "Albus Dumbledore"       "Argus Filch"           
##  [85,] "Albus Dumbledore"       "Nicolas Flamel"        
##  [86,] "Albus Dumbledore"       "Cornelius Fudge"       
##  [87,] "Albus Dumbledore"       "Hermione Granger"      
##  [88,] "Albus Dumbledore"       "Rubeus Hagrid"         
##  [89,] "Albus Dumbledore"       "Bellatrix Lestrange"   
##  [90,] "Albus Dumbledore"       "Remus Lupin"           
##  [91,] "Albus Dumbledore"       "Olympe Maxime"         
##  [92,] "Albus Dumbledore"       "Minerva McGonagall"    
##  [93,] "Albus Dumbledore"       "Alastor Moody"         
##  [94,] "Albus Dumbledore"       "Peter Pettigrew"       
##  [95,] "Albus Dumbledore"       "Harry Potter"          
##  [96,] "Albus Dumbledore"       "James Potter"          
##  [97,] "Albus Dumbledore"       "Lily Potter"           
##  [98,] "Albus Dumbledore"       "Quirinus Quirrell"     
##  [99,] "Albus Dumbledore"       "Lord Voldemort"        
## [100,] "Albus Dumbledore"       "Rita Skeeter"          
## [101,] "Albus Dumbledore"       "Severus Snape"         
## [102,] "Albus Dumbledore"       "Dolores Janes Umbridge"
## [103,] "Albus Dumbledore"       "Arthur Weasley"        
## [104,] "Albus Dumbledore"       "Bill Weasley"          
## [105,] "Albus Dumbledore"       "Charlie Weasley"       
## [106,] "Albus Dumbledore"       "Fred Weasley"          
## [107,] "Albus Dumbledore"       "George Weasley"        
## [108,] "Albus Dumbledore"       "Ginny Weasley"         
## [109,] "Albus Dumbledore"       "Molly Weasley"         
## [110,] "Albus Dumbledore"       "Percy Weasley"         
## [111,] "Albus Dumbledore"       "Ron Weasley"           
## [112,] "Dudley Dursley"         "Petunia Dursley"       
## [113,] "Dudley Dursley"         "Vernon Dursley"        
## [114,] "Dudley Dursley"         "Rubeus Hagrid"         
## [115,] "Dudley Dursley"         "Harry Potter"          
## [116,] "Petunia Dursley"        "Vernon Dursley"        
## [117,] "Petunia Dursley"        "Harry Potter"          
## [118,] "Petunia Dursley"        "Lily Potter"           
## [119,] "Vernon Dursley"         "Harry Potter"          
## [120,] "Argus Filch"            "Hermione Granger"      
## [121,] "Argus Filch"            "Rubeus Hagrid"         
## [122,] "Argus Filch"            "Minerva McGonagall"    
## [123,] "Argus Filch"            "Peter Pettigrew"       
## [124,] "Argus Filch"            "Harry Potter"          
## [125,] "Argus Filch"            "James Potter"          
## [126,] "Argus Filch"            "Severus Snape"         
## [127,] "Argus Filch"            "Dolores Janes Umbridge"
## [128,] "Argus Filch"            "Fred Weasley"          
## [129,] "Argus Filch"            "George Weasley"        
## [130,] "Argus Filch"            "Ron Weasley"           
## [131,] "Seamus Finnigan"        "Hermione Granger"      
## [132,] "Seamus Finnigan"        "Neville Longbottom"    
## [133,] "Seamus Finnigan"        "Luna Lovegood"         
## [134,] "Seamus Finnigan"        "Harry Potter"          
## [135,] "Seamus Finnigan"        "Ginny Weasley"         
## [136,] "Seamus Finnigan"        "Ron Weasley"           
## [137,] "Cornelius Fudge"        "Lucius Malfoy"         
## [138,] "Cornelius Fudge"        "Harry Potter"          
## [139,] "Cornelius Fudge"        "Dolores Janes Umbridge"
## [140,] "Cornelius Fudge"        "Arthur Weasley"        
## [141,] "Cornelius Fudge"        "Percy Weasley"         
## [142,] "Goyle Sr."              "Gregory Goyle"         
## [143,] "Goyle Sr."              "Lord Voldemort"        
## [144,] "Gregory Goyle"          "Hermione Granger"      
## [145,] "Gregory Goyle"          "Draco Malfoy"          
## [146,] "Gregory Goyle"          "Harry Potter"          
## [147,] "Gregory Goyle"          "Lord Voldemort"        
## [148,] "Gregory Goyle"          "Ron Weasley"           
## [149,] "Hermione Granger"       "Rubeus Hagrid"         
## [150,] "Hermione Granger"       "Viktor Krum"           
## [151,] "Hermione Granger"       "Neville Longbottom"    
## [152,] "Hermione Granger"       "Luna Lovegood"         
## [153,] "Hermione Granger"       "Draco Malfoy"          
## [154,] "Hermione Granger"       "Minerva McGonagall"    
## [155,] "Hermione Granger"       "Alastor Moody"         
## [156,] "Hermione Granger"       "Peter Pettigrew"       
## [157,] "Hermione Granger"       "Harry Potter"          
## [158,] "Hermione Granger"       "Quirinus Quirrell"     
## [159,] "Hermione Granger"       "Lord Voldemort"        
## [160,] "Hermione Granger"       "Severus Snape"         
## [161,] "Hermione Granger"       "Dolores Janes Umbridge"
## [162,] "Hermione Granger"       "Arthur Weasley"        
## [163,] "Hermione Granger"       "Bill Weasley"          
## [164,] "Hermione Granger"       "Charlie Weasley"       
## [165,] "Hermione Granger"       "Fred Weasley"          
## [166,] "Hermione Granger"       "George Weasley"        
## [167,] "Hermione Granger"       "Ginny Weasley"         
## [168,] "Hermione Granger"       "Molly Weasley"         
## [169,] "Hermione Granger"       "Ron Weasley"           
## [170,] "Hermione Granger"       "Dobby"                 
## [171,] "Hermione Granger"       "Fluffy"                
## [172,] "Hermione Granger"       "Aragog"                
## [173,] "Hermione Granger"       "Grawp"                 
## [174,] "Rubeus Hagrid"          "Neville Longbottom"    
## [175,] "Rubeus Hagrid"          "Olympe Maxime"         
## [176,] "Rubeus Hagrid"          "Minerva McGonagall"    
## [177,] "Rubeus Hagrid"          "Harry Potter"          
## [178,] "Rubeus Hagrid"          "Lord Voldemort"        
## [179,] "Rubeus Hagrid"          "Severus Snape"         
## [180,] "Rubeus Hagrid"          "Ron Weasley"           
## [181,] "Rubeus Hagrid"          "Fluffy"                
## [182,] "Rubeus Hagrid"          "Aragog"                
## [183,] "Rubeus Hagrid"          "Grawp"                 
## [184,] "Igor Karkaroff"         "Viktor Krum"           
## [185,] "Igor Karkaroff"         "Olympe Maxime"         
## [186,] "Igor Karkaroff"         "Lord Voldemort"        
## [187,] "Viktor Krum"            "Harry Potter"          
## [188,] "Bellatrix Lestrange"    "Lucius Malfoy"         
## [189,] "Bellatrix Lestrange"    "Narcissa Malfoy"       
## [190,] "Bellatrix Lestrange"    "Harry Potter"          
## [191,] "Bellatrix Lestrange"    "Lord Voldemort"        
## [192,] "Bellatrix Lestrange"    "Nymphadora Tonks"      
## [193,] "Bellatrix Lestrange"    "Molly Weasley"         
## [194,] "Bellatrix Lestrange"    "Ron Weasley"           
## [195,] "Bellatrix Lestrange"    "Dobby"                 
## [196,] "Alice Longbottom"       "Frank Longbottom"      
## [197,] "Alice Longbottom"       "Neville Longbottom"    
## [198,] "Frank Longbottom"       "Neville Longbottom"    
## [199,] "Frank Longbottom"       "Lord Voldemort"        
## [200,] "Neville Longbottom"     "Luna Lovegood"         
## [201,] "Neville Longbottom"     "Draco Malfoy"          
## [202,] "Neville Longbottom"     "Harry Potter"          
## [203,] "Neville Longbottom"     "Lord Voldemort"        
## [204,] "Neville Longbottom"     "Ron Weasley"           
## [205,] "Luna Lovegood"          "Xenophilius Lovegood"  
## [206,] "Luna Lovegood"          "Harry Potter"          
## [207,] "Luna Lovegood"          "Ron Weasley"           
## [208,] "Remus Lupin"            "Minerva McGonagall"    
## [209,] "Remus Lupin"            "Peter Pettigrew"       
## [210,] "Remus Lupin"            "Harry Potter"          
## [211,] "Remus Lupin"            "James Potter"          
## [212,] "Remus Lupin"            "Lord Voldemort"        
## [213,] "Remus Lupin"            "Nymphadora Tonks"      
## [214,] "Remus Lupin"            "Fred Weasley"          
## [215,] "Remus Lupin"            "George Weasley"        
## [216,] "Remus Lupin"            "Ginny Weasley"         
## [217,] "Remus Lupin"            "Ron Weasley"           
## [218,] "Draco Malfoy"           "Lucius Malfoy"         
## [219,] "Draco Malfoy"           "Narcissa Malfoy"       
## [220,] "Draco Malfoy"           "Harry Potter"          
## [221,] "Draco Malfoy"           "Ron Weasley"           
## [222,] "Draco Malfoy"           "Dobby"                 
## [223,] "Lucius Malfoy"          "Narcissa Malfoy"       
## [224,] "Lucius Malfoy"          "Harry Potter"          
## [225,] "Lucius Malfoy"          "Lord Voldemort"        
## [226,] "Lucius Malfoy"          "Arthur Weasley"        
## [227,] "Lucius Malfoy"          "Molly Weasley"         
## [228,] "Lucius Malfoy"          "Ron Weasley"           
## [229,] "Lucius Malfoy"          "Dobby"                 
## [230,] "Narcissa Malfoy"        "Lord Voldemort"        
## [231,] "Minerva McGonagall"     "Harry Potter"          
## [232,] "Minerva McGonagall"     "Lord Voldemort"        
## [233,] "Minerva McGonagall"     "Dolores Janes Umbridge"
## [234,] "Minerva McGonagall"     "Ron Weasley"           
## [235,] "Alastor Moody"          "Harry Potter"          
## [236,] "Alastor Moody"          "Lord Voldemort"        
## [237,] "Alastor Moody"          "Arthur Weasley"        
## [238,] "Alastor Moody"          "Molly Weasley"         
## [239,] "Alastor Moody"          "Ron Weasley"           
## [240,] "Peter Pettigrew"        "Harry Potter"          
## [241,] "Peter Pettigrew"        "James Potter"          
## [242,] "Peter Pettigrew"        "Lily Potter"           
## [243,] "Peter Pettigrew"        "Lord Voldemort"        
## [244,] "Peter Pettigrew"        "Fred Weasley"          
## [245,] "Peter Pettigrew"        "George Weasley"        
## [246,] "Peter Pettigrew"        "Ginny Weasley"         
## [247,] "Peter Pettigrew"        "Ron Weasley"           
## [248,] "Harry Potter"           "James Potter"          
## [249,] "Harry Potter"           "Lily Potter"           
## [250,] "Harry Potter"           "Quirinus Quirrell"     
## [251,] "Harry Potter"           "Lord Voldemort"        
## [252,] "Harry Potter"           "Rita Skeeter"          
## [253,] "Harry Potter"           "Severus Snape"         
## [254,] "Harry Potter"           "Dolores Janes Umbridge"
## [255,] "Harry Potter"           "Arthur Weasley"        
## [256,] "Harry Potter"           "Bill Weasley"          
## [257,] "Harry Potter"           "Charlie Weasley"       
## [258,] "Harry Potter"           "Fred Weasley"          
## [259,] "Harry Potter"           "George Weasley"        
## [260,] "Harry Potter"           "Ginny Weasley"         
## [261,] "Harry Potter"           "Molly Weasley"         
## [262,] "Harry Potter"           "Ron Weasley"           
## [263,] "Harry Potter"           "Dobby"                 
## [264,] "Harry Potter"           "Fluffy"                
## [265,] "Harry Potter"           "Hedwig"                
## [266,] "Harry Potter"           "Moaning Myrtle"        
## [267,] "Harry Potter"           "Aragog"                
## [268,] "Harry Potter"           "Grawp"                 
## [269,] "James Potter"           "Lily Potter"           
## [270,] "James Potter"           "Lord Voldemort"        
## [271,] "Lily Potter"            "Lord Voldemort"        
## [272,] "Lily Potter"            "Severus Snape"         
## [273,] "Quirinus Quirrell"      "Lord Voldemort"        
## [274,] "Tom Riddle Sr."         "Mary Riddle"           
## [275,] "Tom Riddle Sr."         "Lord Voldemort"        
## [276,] "Mary Riddle"            "Lord Voldemort"        
## [277,] "Lord Voldemort"         "Severus Snape"         
## [278,] "Lord Voldemort"         "Nymphadora Tonks"      
## [279,] "Lord Voldemort"         "Bill Weasley"          
## [280,] "Lord Voldemort"         "Charlie Weasley"       
## [281,] "Lord Voldemort"         "Fred Weasley"          
## [282,] "Lord Voldemort"         "George Weasley"        
## [283,] "Lord Voldemort"         "Ginny Weasley"         
## [284,] "Lord Voldemort"         "Molly Weasley"         
## [285,] "Lord Voldemort"         "Ron Weasley"           
## [286,] "Severus Snape"          "Fred Weasley"          
## [287,] "Severus Snape"          "George Weasley"        
## [288,] "Severus Snape"          "Ginny Weasley"         
## [289,] "Severus Snape"          "Ron Weasley"           
## [290,] "Dolores Janes Umbridge" "Ron Weasley"           
## [291,] "Arthur Weasley"         "Bill Weasley"          
## [292,] "Arthur Weasley"         "Charlie Weasley"       
## [293,] "Arthur Weasley"         "Fred Weasley"          
## [294,] "Arthur Weasley"         "George Weasley"        
## [295,] "Arthur Weasley"         "Ginny Weasley"         
## [296,] "Arthur Weasley"         "Molly Weasley"         
## [297,] "Arthur Weasley"         "Percy Weasley"         
## [298,] "Arthur Weasley"         "Ron Weasley"           
## [299,] "Bill Weasley"           "Charlie Weasley"       
## [300,] "Bill Weasley"           "Fred Weasley"          
## [301,] "Bill Weasley"           "George Weasley"        
## [302,] "Bill Weasley"           "Ginny Weasley"         
## [303,] "Bill Weasley"           "Molly Weasley"         
## [304,] "Bill Weasley"           "Percy Weasley"         
## [305,] "Bill Weasley"           "Ron Weasley"           
## [306,] "Charlie Weasley"        "Fred Weasley"          
## [307,] "Charlie Weasley"        "George Weasley"        
## [308,] "Charlie Weasley"        "Ginny Weasley"         
## [309,] "Charlie Weasley"        "Molly Weasley"         
## [310,] "Charlie Weasley"        "Percy Weasley"         
## [311,] "Charlie Weasley"        "Ron Weasley"           
## [312,] "Fred Weasley"           "George Weasley"        
## [313,] "Fred Weasley"           "Ginny Weasley"         
## [314,] "Fred Weasley"           "Molly Weasley"         
## [315,] "Fred Weasley"           "Percy Weasley"         
## [316,] "Fred Weasley"           "Ron Weasley"           
## [317,] "George Weasley"         "Ginny Weasley"         
## [318,] "George Weasley"         "Molly Weasley"         
## [319,] "George Weasley"         "Percy Weasley"         
## [320,] "George Weasley"         "Ron Weasley"           
## [321,] "Ginny Weasley"          "Molly Weasley"         
## [322,] "Ginny Weasley"          "Percy Weasley"         
## [323,] "Ginny Weasley"          "Ron Weasley"           
## [324,] "Molly Weasley"          "Percy Weasley"         
## [325,] "Molly Weasley"          "Ron Weasley"           
## [326,] "Percy Weasley"          "Ron Weasley"           
## [327,] "Ron Weasley"            "Dobby"                 
## [328,] "Ron Weasley"            "Fluffy"                
## [329,] "Ron Weasley"            "Aragog"                
## [330,] "Ron Weasley"            "Grawp"

Node importance: Centrality measures

Overall Centrality

Centrality describes the number of edges from nodes. High centrality networks have few nodes with many connections, low centrality networks have many nodes with similar numbers of edges.

For the whole network, we can calculate centrality by degree (centr_degree()), closeness (centr_clo()), eigenvector centrality (centr_eigen()) or betweenness (centr_betw()) of vertices.

In this case, centrality by degree and closeness result in close numbers. However, all centrality measures are below 1, which would mean that the network has many nodes with similar number of edges. This makes sense, as the diameter is only equal to 4 edges, with the average shortest path at 2.

#centrality by degree
centr_degree(g11,mode="total")$centralization
## [1] 0.5913462
#centrality by closeness
centr_clo(g11, mode="total")$centralization
## [1] 0.6047131
#centrality by eigenvector
centr_eigen(g11, directed=FALSE)$centralization
## [1] 0.717455
#centrality by betweenness
centr_betw(g11, "total")$centralization
## [1] 0.2697674

Plotting Highest Degree Centrality

Visualization of the characters with the highest degree centrality sorted in decreasing order (clockwise). The name of the character is centered in the node (Harry Potter having the highest degree centrality and Nicolas Flamel the lowest).

#layout of RMardown
par(mar=c(1,1,0,0))

visualize_graph(g11 , centrality.type="Degree Centrality")

Network Component Analysis

Centrality is defined as a measure for identifying the most important vertices within a network in graph theory. Several centrality types have been provided to compute central nodes by different formulas, while some analysis are needed to evaluate the most informative ones.

Before further calculating centrality measures, we need to extract the components of the graph to then, identify correctly the recommended the best fitted centrality measures according to this graph.

Segregation of other graph formats

This function extracts the components of other formats of graph. For illustration, we convert the Harry Potter graph to an edge list to be able to use it for this function.

g11_edgelist<-as_edgelist(g11)

misc_extract_components(g11_edgelist)
## [[1]]
## IGRAPH 874d4ac DN-- 65 330 -- 
## + attr: name (v/c)
## + edges from 874d4ac (vertex names):
##  [1] Regulus Arcturus Black->Sirius Black       
##  [2] Regulus Arcturus Black->Vincent Crabbe Sr. 
##  [3] Regulus Arcturus Black->Bellatrix Lestrange
##  [4] Regulus Arcturus Black->Lord Voldemort     
##  [5] Sirius Black          ->Albus Dumbledore   
##  [6] Sirius Black          ->Argus Filch        
##  [7] Sirius Black          ->Hermione Granger   
##  [8] Sirius Black          ->Bellatrix Lestrange
## + ... omitted several edges

Centrality Measure Analysis

All of the introduced centrality measures are not appropriate for all types of networks. So, to figure out which of them is suitable, proper_centralities is specified. This function distinguishes proper centrality types based on network topology. It returns the full names of suitable centrality types for the input graph.

proper_centralities(g11)
##  [1] "subgraph centrality scores"                      
##  [2] "Topological Coefficient"                         
##  [3] "Average Distance"                                
##  [4] "Barycenter Centrality"                           
##  [5] "BottleNeck Centrality"                           
##  [6] "Centroid value"                                  
##  [7] "Closeness Centrality (Freeman)"                  
##  [8] "ClusterRank"                                     
##  [9] "Decay Centrality"                                
## [10] "Degree Centrality"                               
## [11] "Diffusion Degree"                                
## [12] "DMNC - Density of Maximum Neighborhood Component"
## [13] "Eccentricity Centrality"                         
## [14] "Harary Centrality"                               
## [15] "eigenvector centralities"                        
## [16] "K-core Decomposition"                            
## [17] "Geodesic K-Path Centrality"                      
## [18] "Katz Centrality (Katz Status Index)"             
## [19] "Kleinberg's authority centrality scores"         
## [20] "Kleinberg's hub centrality scores"               
## [21] "clustering coefficient"                          
## [22] "Lin Centrality"                                  
## [23] "Lobby Index (Centrality)"                        
## [24] "Markov Centrality"                               
## [25] "Radiality Centrality"                            
## [26] "Shortest-Paths Betweenness Centrality"           
## [27] "Current-Flow Closeness Centrality"               
## [28] "Closeness centrality (Latora)"                   
## [29] "Communicability Betweenness Centrality"          
## [30] "Community Centrality"                            
## [31] "Cross-Clique Connectivity"                       
## [32] "Entropy Centrality"                              
## [33] "EPC - Edge Percolated Component"                 
## [34] "Laplacian Centrality"                            
## [35] "Leverage Centrality"                             
## [36] "MNC - Maximum Neighborhood Component"            
## [37] "Hubbell Index"                                   
## [38] "Semi Local Centrality"                           
## [39] "Closeness Vitality"                              
## [40] "Residual Closeness Centrality"                   
## [41] "Stress Centrality"                               
## [42] "Load Centrality"                                 
## [43] "Flow Betweenness Centrality"                     
## [44] "Information Centrality"                          
## [45] "Dangalchev Closeness Centrality"                 
## [46] "Group Centrality"                                
## [47] "Harmonic Centrality"                             
## [48] "Local Bridging Centrality"                       
## [49] "Wiener Index Centrality"

Centrality Computations

In the next step, proper centralities for the network are defined. In order to compute proper centrality types resulting from the proper_centralities, you can use calculate_centralities function as below.

pr_cent<-proper_centralities(g11)
##  [1] "subgraph centrality scores"                      
##  [2] "Topological Coefficient"                         
##  [3] "Average Distance"                                
##  [4] "Barycenter Centrality"                           
##  [5] "BottleNeck Centrality"                           
##  [6] "Centroid value"                                  
##  [7] "Closeness Centrality (Freeman)"                  
##  [8] "ClusterRank"                                     
##  [9] "Decay Centrality"                                
## [10] "Degree Centrality"                               
## [11] "Diffusion Degree"                                
## [12] "DMNC - Density of Maximum Neighborhood Component"
## [13] "Eccentricity Centrality"                         
## [14] "Harary Centrality"                               
## [15] "eigenvector centralities"                        
## [16] "K-core Decomposition"                            
## [17] "Geodesic K-Path Centrality"                      
## [18] "Katz Centrality (Katz Status Index)"             
## [19] "Kleinberg's authority centrality scores"         
## [20] "Kleinberg's hub centrality scores"               
## [21] "clustering coefficient"                          
## [22] "Lin Centrality"                                  
## [23] "Lobby Index (Centrality)"                        
## [24] "Markov Centrality"                               
## [25] "Radiality Centrality"                            
## [26] "Shortest-Paths Betweenness Centrality"           
## [27] "Current-Flow Closeness Centrality"               
## [28] "Closeness centrality (Latora)"                   
## [29] "Communicability Betweenness Centrality"          
## [30] "Community Centrality"                            
## [31] "Cross-Clique Connectivity"                       
## [32] "Entropy Centrality"                              
## [33] "EPC - Edge Percolated Component"                 
## [34] "Laplacian Centrality"                            
## [35] "Leverage Centrality"                             
## [36] "MNC - Maximum Neighborhood Component"            
## [37] "Hubbell Index"                                   
## [38] "Semi Local Centrality"                           
## [39] "Closeness Vitality"                              
## [40] "Residual Closeness Centrality"                   
## [41] "Stress Centrality"                               
## [42] "Load Centrality"                                 
## [43] "Flow Betweenness Centrality"                     
## [44] "Information Centrality"                          
## [45] "Dangalchev Closeness Centrality"                 
## [46] "Group Centrality"                                
## [47] "Harmonic Centrality"                             
## [48] "Local Bridging Centrality"                       
## [49] "Wiener Index Centrality"

The following function has the ability to specify some centrality types that are not favored to calculate by the conclude argument. Here, we will select the first ten centrality measures.

calc_cent<-calculate_centralities(g11, include = pr_cent[1:10])

Recognition of most informative measures

From this algorithm, the result is a list of computed centralities.

The following is a display of the most informative centrality measures based on principal component analysis. The red line indicates the random threshold of contribution. This barplot represents contribution of variable values based on the number of dimensions.

pca_centralities(calc_cent)

Now that we have the top 10 centrality measures, we will look at the correlation within each centrality measure and choose measures that aren’t highly correlated to each other. When they are highly correlated, it means that they will provide the same kind of information and will only be regarded as repetitive.

Correlation between computed centrality measures

To comprehend pair correlation among centralities, visualize_correlations method is appropriate; it is able to specify the type of correlation which are interesting to obtain and analyse.

visualize_correlations(calc_cent,"pearson")

#A display of correlation among computed centrality measures. The red to blue highlighted circles represent the top to bottom Pearson correlation coefficients(Benesty et al. 2009) which differ from -1 to 1. The higher the value becomes larger, circles' sizes get larger too.

As we can see, there are high levels of correlations between:

  • Closeness, Decay and Barycenter; these were the top 3 measures from which we will only choose closeness
  • Degree and subgraph; choose degree
  • Topological
  • Bottleneck

Chosen Centrality Measures:

Closeness

Closeness centrality measures the average distance from any given vertex to all other vertices. The closeness list is dominated exclusively by well known characters, most of them being aligned as good and from Gryffindor. This is an indicator that House and Alignment are closely aligned (connected).

#create a new dataframe for top 20 centralities from the keys dataframe
keys_top20_centrality<-keys

#keep only important columns to show
keys_top20_centrality$Color<-NULL
keys_top20_centrality$id<-NULL
keys_top20_centrality$Gender_Male<-NULL

#assign closeness value to each actor
keys_top20_centrality$closeness <- igraph::closeness(g11, mode = "total")

#order the dataframe based on decreasing order in closeness
head(keys_top20_centrality[order(-keys_top20_centrality$closeness),],n=20)
##              Character Alignment      House   closeness
## 40        Harry Potter      Good Gryffindor 0.012500000
## 59         Ron Weasley      Good Gryffindor 0.010989011
## 22    Hermione Granger      Good Gryffindor 0.010869565
## 46      Lord Voldemort      Evil  Slytherin 0.010752688
## 12    Albus Dumbledore      Good Gryffindor 0.010204082
## 2         Sirius Black      Good Gryffindor 0.009259259
## 56       Ginny Weasley      Good Gryffindor 0.008928571
## 54        Fred Weasley      Good Gryffindor 0.008849558
## 55      George Weasley      Good Gryffindor 0.008849558
## 57       Molly Weasley      Good Gryffindor 0.008849558
## 29  Neville Longbottom      Good Gryffindor 0.008695652
## 39     Peter Pettigrew      Evil Gryffindor 0.008695652
## 23       Rubeus Hagrid      Good Gryffindor 0.008620690
## 48       Severus Snape      Good  Slytherin 0.008620690
## 26 Bellatrix Lestrange      Evil  Slytherin 0.008547009
## 52        Bill Weasley      Good Gryffindor 0.008547009
## 53     Charlie Weasley      Good Gryffindor 0.008474576
## 32         Remus Lupin      Good Gryffindor 0.008403361
## 37  Minerva McGonagall      Good Gryffindor 0.008403361
## 34       Lucius Malfoy      Evil  Slytherin 0.008333333

Highest Degree

The top 20 list with the highest degree centrality shows the actors with the most links in relation to nodes within the network. In this case, a higher centrality degree is directly related to the number of relationships the characters have with others. Although Hermione is the character with the most relationships (most degrees) and not Harry Potter, because she’s considered the most knowledgeable character in the story line.

Again, the high degree centrality of the top-20 list might be explained by virtue of the dominance of the common House. Furthermore, the dominance of Good Alignment in characters suggests that there are fewer Evil characters than Good characters. If it is assumed that Evil characters are nevertheless required in all Harry Potter films, but considering the movies are on average PG-13, Good characters are more popular. This could be a possible explanation for the high degree values of the top 20 list.

#assign degree value to each actor
keys_top20_centrality$degree<-igraph::degree(g1,mode = "total")

#order the dataframe based on decreasing order in degree
head(keys_top20_centrality[order(-keys_top20_centrality$degree),],n=20)
##             Character Alignment      House   closeness degree
## 22   Hermione Granger      Good Gryffindor 0.010869565     59
## 59        Ron Weasley      Good Gryffindor 0.010989011     57
## 40       Harry Potter      Good Gryffindor 0.012500000     56
## 12   Albus Dumbledore      Good Gryffindor 0.010204082     55
## 46     Lord Voldemort      Evil  Slytherin 0.010752688     46
## 55     George Weasley      Good Gryffindor 0.008849558     35
## 51     Arthur Weasley      Good Gryffindor 0.008333333     34
## 2        Sirius Black      Good Gryffindor 0.009259259     33
## 56      Ginny Weasley      Good Gryffindor 0.008928571     30
## 52       Bill Weasley      Good Gryffindor 0.008547009     28
## 54       Fred Weasley      Good Gryffindor 0.008849558     28
## 53    Charlie Weasley      Good Gryffindor 0.008474576     27
## 57      Molly Weasley      Good Gryffindor 0.008849558     24
## 37 Minerva McGonagall      Good Gryffindor 0.008403361     23
## 39    Peter Pettigrew      Evil Gryffindor 0.008695652     23
## 48      Severus Snape      Good  Slytherin 0.008620690     23
## 58      Percy Weasley      Good Gryffindor 0.007633588     23
## 23      Rubeus Hagrid      Good Gryffindor 0.008620690     21
## 38      Alastor Moody      Good       <NA> 0.008333333     19
## 41       James Potter      Good Gryffindor 0.008064516     18

Topological Coefficient

The topological coefficient is a relative measure for the extent to which a node shares neighbors with other nodes. More precisely, the topological coefficient is the number of neighbors shared between a pair of nodes, x and y, plus one if there is a direct link between them, divided by the number of neighbors of node x. Thus, nodes that have one or no neighbors are assigned a topological coefficient of 0.

In this case, it is normal for Harry Potter, Voldemort, Hermione and Ron to have the highest values, as they share many of the same relationships with other characters and most of the scenes include one of the characters.

#assign topological coefficient value to each actor
keys_top20_centrality$topological<-1/centiserve::topocoefficient(g11)

#order the dataframe based on decreasing order of coefficient
head(keys_top20_centrality[order(-keys_top20_centrality$topological),],n=20)
##               Character Alignment       House   closeness degree
## 40         Harry Potter      Good  Gryffindor 0.012500000     56
## 46       Lord Voldemort      Evil   Slytherin 0.010752688     46
## 22     Hermione Granger      Good  Gryffindor 0.010869565     59
## 59          Ron Weasley      Good  Gryffindor 0.010989011     57
## 12     Albus Dumbledore      Good  Gryffindor 0.010204082     55
## 29   Neville Longbottom      Good  Gryffindor 0.008695652     17
## 5    Vincent Crabbe Sr.      Evil   Slytherin 0.007246377     11
## 2          Sirius Black      Good  Gryffindor 0.009259259     33
## 7  Bartemius Crouch Sr.      Good        <NA> 0.006250000      6
## 23        Rubeus Hagrid      Good  Gryffindor 0.008620690     21
## 26  Bellatrix Lestrange      Evil   Slytherin 0.008547009     16
## 24       Igor Karkaroff   Neutral  Durmstrang 0.006756757      5
## 34        Lucius Malfoy      Evil   Slytherin 0.008333333     15
## 56        Ginny Weasley      Good  Gryffindor 0.008928571     30
## 9        Fleur Delacour      Good Beauxbatons 0.008130081     12
## 57        Molly Weasley      Good  Gryffindor 0.008849558     24
## 8  Bartemius Crouch Jr.      Evil        <NA> 0.008196721     12
## 58        Percy Weasley      Good  Gryffindor 0.007633588     23
## 39      Peter Pettigrew      Evil  Gryffindor 0.008695652     23
## 33         Draco Malfoy      Evil   Slytherin 0.007812500     14
##    topological
## 40    5.440585
## 46    4.779443
## 22    4.750515
## 59    4.607004
## 12    4.280702
## 29    3.834783
## 5     3.735849
## 2     3.490050
## 7     3.448276
## 23    3.325670
## 26    3.289796
## 24    3.288889
## 34    3.200000
## 56    2.983957
## 9     2.929907
## 57    2.919668
## 8     2.887701
## 58    2.882353
## 39    2.879257
## 33    2.861272

BottleNeck Centrality

A bottleneck to a network is a node that has information to the network that is concentrated. The bottleneckness of a node can be calculated using betweenness centrality, which is a measure of a node’s centrality in a network, and equal to the number of shortest paths going through it.

In other words, a node characterized by high bottleneck centrality means that most nodes need to pass through this specific node to follow a certain path (these paths being the shortest paths). Thus, even though Hermione might have the most connections, Harry has more particular connections which requires the information to pass through him instead of Hermione.

#assign degree value to each bottleneck centrality value
keys_top20_centrality$bottleneck <- bottleneck(g11)

#order the dataframe based on decreasing order of bottleneck centrality value
head(keys_top20_centrality[order(-keys_top20_centrality$bottleneck),],n=20)
##                 Character Alignment      House   closeness degree
## 40           Harry Potter      Good Gryffindor 0.012500000     56
## 46         Lord Voldemort      Evil  Slytherin 0.010752688     46
## 22       Hermione Granger      Good Gryffindor 0.010869565     59
## 59            Ron Weasley      Good Gryffindor 0.010989011     57
## 12       Albus Dumbledore      Good Gryffindor 0.010204082     55
## 2            Sirius Black      Good Gryffindor 0.009259259     33
## 5      Vincent Crabbe Sr.      Evil  Slytherin 0.007246377     11
## 29     Neville Longbottom      Good Gryffindor 0.008695652     17
## 26    Bellatrix Lestrange      Evil  Slytherin 0.008547009     16
## 30          Luna Lovegood      Good  Ravenclaw 0.007518797      9
## 58          Percy Weasley      Good Gryffindor 0.007633588     23
## 23          Rubeus Hagrid      Good Gryffindor 0.008620690     21
## 34          Lucius Malfoy      Evil  Slytherin 0.008333333     15
## 35        Narcissa Malfoy      Evil  Slytherin 0.006896552      7
## 17        Seamus Finnigan      Good Gryffindor 0.007633588     10
## 24         Igor Karkaroff   Neutral Durmstrang 0.006756757      5
## 33           Draco Malfoy      Evil  Slytherin 0.007812500     14
## 49       Nymphadora Tonks      Good Hufflepuff 0.006711409      6
## 56          Ginny Weasley      Good Gryffindor 0.008928571     30
## 1  Regulus Arcturus Black      Good  Slytherin 0.006802721      5
##    topological bottleneck
## 40    5.440585         62
## 46    4.779443         59
## 22    4.750515         49
## 59    4.607004         48
## 12    4.280702         34
## 2     3.490050         11
## 5     3.735849          9
## 29    3.834783          8
## 26    3.289796          6
## 30    2.181818          6
## 58    2.882353          6
## 23    3.325670          5
## 34    3.200000          4
## 35    2.311828          4
## 17    2.494118          3
## 24    3.288889          3
## 33    2.861272          3
## 49    1.904762          3
## 56    2.983957          3
## 1     2.074074          2

Other Common Centrality Measures

During our Social Network Analysis Class, we had the opportunity to learn about other common centrality measures that weren’t considered important through the PCA analysis. However, we did want to analyze these measures, as they were essential to our learning curve during our semester.

Betweenness

Betweenness centrality is a metric used to find nodes that serve as a bridge (connector) from one part of the network to another. In other words, betweenness measures the average length of shortest paths that pass through a vertex. Accordingly characters with a high betweenness can be understood as links between different closed clusters of characters.

As we can see, only a few characters have high level of betweenness. On average, if characters have low betweenness measurements, this demonstrates that most of these nodes do not lie on the shortest paths. This goes in hand with the bottleneck centrality measure, where characters that lie more frequently on these paths have a higher probability of being considered bottlenecks for the network (which is true when looking at the first two values of each dataframe).

#create a new dataframe for top 20 centralities from the keys dataframe
keys_top20_others <- keys

#keep only important columns to show
keys_top20_others$Color<-NULL
keys_top20_others$id<-NULL
keys_top20_others$Gender_Male<-NULL

#assign degree value to each bottleneck centrality value
keys_top20_others$betweenness <- igraph::betweenness(g11, directed = FALSE)

#order the dataframe based on decreasing order of bottleneck centrality value
head(keys_top20_others[order(-keys_top20_others$betweenness),],n=20)
##               Character Alignment       House betweenness
## 40         Harry Potter      Good  Gryffindor   568.39191
## 46       Lord Voldemort      Evil   Slytherin   410.15172
## 12     Albus Dumbledore      Good  Gryffindor   202.59718
## 59          Ron Weasley      Good  Gryffindor   198.58285
## 22     Hermione Granger      Good  Gryffindor   189.48922
## 29   Neville Longbottom      Good  Gryffindor    90.23966
## 30        Luna Lovegood      Good   Ravenclaw    63.00000
## 2          Sirius Black      Good  Gryffindor    56.19830
## 23        Rubeus Hagrid      Good  Gryffindor    38.09892
## 26  Bellatrix Lestrange      Evil   Slytherin    34.39321
## 8  Bartemius Crouch Jr.      Evil        <NA>    26.77249
## 5    Vincent Crabbe Sr.      Evil   Slytherin    20.69743
## 58        Percy Weasley      Good  Gryffindor    20.28649
## 34        Lucius Malfoy      Evil   Slytherin    19.94463
## 9        Fleur Delacour      Good Beauxbatons    16.34125
## 39      Peter Pettigrew      Evil  Gryffindor    13.27643
## 56        Ginny Weasley      Good  Gryffindor    13.02037
## 21        Gregory Goyle      Evil   Slytherin    12.09342
## 48        Severus Snape      Good   Slytherin    12.09215
## 24       Igor Karkaroff   Neutral  Durmstrang    10.14327

When plotting the higher values of betweenness in our inital network:

#layout of RMarkdown
par(mar=c(1,1,1,1))

#create variables for the plot
edge_betweenness <- igraph::edge_betweenness(g11, directed = FALSE)
betweenness<-igraph::betweenness(g11, directed = FALSE)

plot(igraph::simplify(g1,edge.attr.comb = "min"),
     layout = mylayout,
     legend = TRUE,
     vertex.label = V(g1)$Character,
     vertex.color = V(g1)$Color, 
     vertex.size = betweenness * 0.001, 
     vertex.frame.color = "gray", 
     vertex.label.color = "black",
     vertex.label.cex = 0.6,
     edge.width = edge_betweenness * 0.12,
     edge.color = "gray",
     edge.lty = E(g1)$lty,
     asp = 0.75,
     rescale = FALSE,
     ylim = c(-4.5,4.5),
     xlim = c(-2,2))
legend("top", legend = "", cex = 0.95, bty = "n", ncol = 1,
       title = "Harry Potter's Character Edge Betweenness")

Top 10 Strongest 2-Character Betweenness

Having a closer look at the betweenness topic, we can also explore the strongest 2-character betweenness. The 2-Character betweenness represents the top 10 most popular relationships where the most frequent shortest paths pass through. From this dataframe, we can infer that the highest values are given to characters that have strong relationships and one on the characters in the relationship, is only connected to the other character (who then has a high degree centrality). For example, Harry Potter and Hedwig have a high in betweenness because Hedwig is only connected to Harry, but Harry is one of the most connected characters.

data.frame(edge = attr(E(g11), "vnames"),
           betweenness = edge_betweenness) %>%
  tibble::rownames_to_column() %>%
  arrange(-betweenness) %>%
  .[1:10, ]
##    rowname                                edge betweenness
## 1       85     Albus Dumbledore|Nicolas Flamel    64.00000
## 2      205  Luna Lovegood|Xenophilius Lovegood    64.00000
## 3      265                 Harry Potter|Hedwig    64.00000
## 4      266         Harry Potter|Moaning Myrtle    64.00000
## 5      275       Tom Riddle Sr.|Lord Voldemort    63.00000
## 6      276          Mary Riddle|Lord Voldemort    63.00000
## 7      197 Alice Longbottom|Neville Longbottom    54.47857
## 8      199     Frank Longbottom|Lord Voldemort    54.03512
## 9      186       Igor Karkaroff|Lord Voldemort    53.75210
## 10     206          Luna Lovegood|Harry Potter    51.28337

Graph Theory

Eigenvector

Eigenvector centrality is a measure of the influence of a node in a network. Relative scores are assigned to all nodes in the network based on the concept that connections to high-scoring nodes contribute more to the score of the node in question than equal connections to low-scoring nodes. A high eigenvector score means that a node is connected to many nodes who themselves have high scores. PageRank and the Katz centrality are variants of the eigenvector centrality. PageRank won’t be computed as it is for often used to rank web pages and for directed graphs.

Eigenvector centrality works well only if the graph is (strongly) connected. Real undirected networks typically have a large connected component, of size proportional to the network size. Therefore, because our graph is undirected, we do not need to find the Katz centrality measure, as it is used mostly for directed graphs.

If a directed network is not strongly connected, only vertices that are in strongly connected components or in the out-component of such components can have non-zero eigenvector centrality. The other vertices, such as those in the in-components of strongly connected components, all have, with little justification, null centrality. This happens because nodes with no incoming edges have, by definition, a null eigenvector centrality score, and so have nodes that are pointed to by only nodes with a null centrality score.

Katz centrality: A way to work around this problem is to give each node a small amount of centrality for free, regardless of the position of the vertex in the network. Hence, each node has a minimum, positive amount of centrality that it can transfer to other nodes by referring to them.

However, because we have an undirected network, we only computed the eigenvector centralities. From our results, we can see that the top characters are from the Weasley family. This family has ties with important characters and are considered one of the prominent wizarding families.

#assign degree value to each bottleneck centrality value
keys_top20_others$eigen<-igraph::eigen_centrality(g1)$vector

#order the dataframe based on decreasing order of bottleneck centrality value
head(keys_top20_others[order(-keys_top20_others$eigen),],n=20)
##                 Character Alignment      House betweenness     eigen
## 22       Hermione Granger      Good Gryffindor  189.489217 1.0000000
## 55         George Weasley      Good Gryffindor    6.508347 0.9511415
## 59            Ron Weasley      Good Gryffindor  198.582847 0.9288641
## 12       Albus Dumbledore      Good Gryffindor  202.597178 0.9242241
## 51         Arthur Weasley      Good Gryffindor    6.616091 0.9238878
## 52           Bill Weasley      Good Gryffindor    3.465663 0.8077169
## 53        Charlie Weasley      Good Gryffindor    1.807752 0.7994759
## 56          Ginny Weasley      Good Gryffindor   13.020372 0.7737188
## 40           Harry Potter      Good Gryffindor  568.391905 0.7595342
## 54           Fred Weasley      Good Gryffindor    6.508347 0.7492480
## 46         Lord Voldemort      Evil  Slytherin  410.151718 0.6487222
## 57          Molly Weasley      Good Gryffindor    8.878000 0.6291314
## 58          Percy Weasley      Good Gryffindor   20.286493 0.6268225
## 2            Sirius Black      Good Gryffindor   56.198299 0.6151905
## 37     Minerva McGonagall      Good Gryffindor    4.955393 0.5625002
## 48          Severus Snape      Good  Slytherin   12.092155 0.5270981
## 38          Alastor Moody      Good       <NA>    2.959805 0.4834333
## 39        Peter Pettigrew      Evil Gryffindor   13.276428 0.4563157
## 50 Dolores Janes Umbridge      Evil  Slytherin    2.850000 0.4167115
## 43      Quirinus Quirrell      Evil  Ravenclaw    0.000000 0.4081002

Network Measures: Transitivity and Reciprocity

There is no reciprocity for undirected graph. Thus, we will only compute transitivity.

Transitivity

Transitivity measures the probability that the adjacent vertices of a vertex are connected. This is sometimes also called the clustering coefficient. The clustering coefficient measures the transitivity of a network, that is how connected closed groups of vertices are with each other. The global clustering coefficient gives an indication of the overall clustering in the network, while the local clustering coefficient gives an indication of the embeddedness of single nodes.

This suggests that there are more tightly knit groups of actors by virtue of shared Alignment.

#calculate global transitivity in the dataframe
transitivity(g11, type="global")
## [1] 0.4133759
#calculate local transitivity in the dataframe
transitivity(g11, type="localaverageundirected")
## [1] 0.6518034

Network Models: Real World networks

Erdos-Renyi (random graphs)

In this section, we will explore the Erdos-Renyi model and compare its structural properties to those of real-world networks that we graphed above.

#For our Erdos-Renyi model, we used the sample_gnm function from which we used the number of nodes in the networks to create our new models. 
vertices_characters<-vcount(g11)
edges_characters<-ecount(g11)

er_potter<-sample_gnm(vertices_characters,edges_characters, directed = FALSE)

Degree distribution of Erdos-Renyi (ER) is now normally distributed versus the real-world networks (original distribution of Harry Potter’s network was right skewed), where degrees between 5 and 15 are the most frequent.

#Degree Distribution

deg_erpotter<-igraph::degree(er_potter)
hist(igraph::degree(er_potter), xlim = c(0,20), ylim = c(0,20), col = "tomato")

The average path length and diameter have not changed between both model, with 2 and 4. These values may not change when comparing smaller networks together; both networks are as well connected.

#Network Diameter and Average Path Length

mean_distance(er_potter, directed=F)
## [1] 2.020192
diameter(er_potter)
## [1] 4

When applying the Erdos-Renyi models, the local and global clustering coefficient becomes almost equal to 0, removing any types of triangular connections or relationships that existed between the nodes whether local or global. Furthermore, the almost 0 values for the cluster coefficient for the Erdos-Rényi model demonstrates a lack of clusters in this network. This signifies that clusters found in the real world networks would not necessarily occur given random conditions.

#(Global and Local) Clustering Coefficient

global_er_potter<-transitivity(er_potter) #GLOBAL
global_er_potter
## [1] 0.1563253
local_er_potter<-transitivity(er_potter, type='localaverageundirected') #LOCAL
local_er_potter
## [1] 0.1635723

In conclusion, the Erdos-Renyi model doesn’t describe real life networks as well. Access to larger networks (social networks, power networks, the world wide web, etc.) have made clear that many previous graph-theory models which were used to approximate networks were incorrect - the most famous of which, the Erdos-Renyi model, failed to replicate the clustering, triadic closure, and hubs seen in real-world networks. As a result, there were two notable models created in an attempt to fix some of the problems Erdos-Renyi had: The Watts-Strogatz model and the Barabasi-Albert model.

Watts Strogatz (small world)

The Watts-Strogatz model is a random graph generation model that produces graphs with small-world properties, including short average path lengths and high clustering.

They start with the lattice model that has high clustering and high mean path length. Then, add to the model a probability p that an edge is rewired, meaning that the edge is disconnected from one of its nodes and then randomly connected to another node anywhere in the network. Each edge is chosen to be rewired independent with probability p.

#create small world network and plot to see what it looks like
g.ws <- sample_smallworld(dim=2, size=65, nei=1, p=0.015)
plot(g.ws, vertex.size=6, vertex.label=NA, layout=layout_in_circle)

When the probability p is low, then most connections are still the original local connections that they connect nodes that are nearby in the lattice. However, some of the edges that have been rewired might turn into long distance connections that connect nodes that are far away from each other in the lattice. These long distance connections, or shortcuts, immediately create a short distance between the nodes around either end of the shortcut.

Originally, each node was symmetrically connected to its nearest neighbors along the ring. But then, each edge was rewired with probability 1/65. If an edge was selected for rewiring, one end of the edge was disconnected from a node and reconnected with a randomly chosen node. When probability is large (like in our graph), the transivity becomes low.

This model does not replicate the real world network, as it’s mean path length is around 5 times longer. This is because of the rewiring of the edges, which creates longer paths on average.

transitivity(g.ws) #clustering coefficient
## [1] 0.0002345307
mean_distance(g.ws) #diameter
## [1] 12.0706

Preferential Attachment: Barabasi

The Barabási-Albert (BA) model is an algorithm for generating random scale-free networks using a preferential attachment mechanism. The BA model tries to explain the existence of few nodes with high degree in real networks.

par(mar=c(1,1,1,1))

#create BA network and plot to see what it looks like
g.ba <-  sample_pa(n=65, power=1, m=1,  directed=F)
plot(g.ba, vertex.size=6, vertex.label=NA)

Many observed networks (at least approximately) fall into the class of scale-free networks, meaning that they have power-law (or scale-free) degree distributions, while random graph models such as the Erdos-Rényi (ER) model and the Watts-Strogatz (WS) model do not exhibit power laws.

Even though the BA’s network degree distribution has the same right skewed shape, there are too many node degrees between 0 and 2 degrees. In addition, the BA model doesn’t represent the outliers that we have in the real world networks (nodes of degrees of 50 for example).

hist(igraph::degree(g.ba), col="tomato", xlab="Degree", ylab="Frequency", main="", ylim=c(0,60), xlim=c(1,10))

Information Diffusion

Group Centrality Measure

The basic idea of measuring the group-level centrality is to treat a group of nodes as a large pseudo-node. We propose several methods to measure the tie status between this pseudo node and other nodes, responding to several common edge value interpretations (An and Liu, 2015).

In a context, centrality measures may be insufficient to describe the data.

None of these packages (network, igraph, statnet) provide a comprehensive toolbox to calculate group centrality measures and to identify key players, who constitute the most central group, in a network. Determining the key players in a network is very important because interventions rely on key players to facilitate the intervention.

The algorithm for identifying key players in package keyplayer essentially consists of three steps. First, users choose a metric to measure centrality in a network. Second, the algorithm (specifically the kpcent function) will randomly pick a group of players and measure their group centrality. Third, the algorithm (specifically the kpset function) will select the group of players with the highest group centrality as the desired key players.

The keys players, 15 and 32, in our network belong to Vernon Dursley and Remus Lupin. This means that if a message needed to be passed around within the network, the speed at which all characters would know the message would be the highest with these characters. This is surprising, as both these characters are not the main characters of the story.

kpset(g11_ajd, size = 2, type = "diffusion", cmode = "all", method = "max")$keyplayers
## [1] 15 32
kpset(g11_ajd, size = 2, type = "diffusion", cmode = "all", M = 1, binary = TRUE)$keyplayers
## [1] 15 32

When calculating the group-level centraility scores of both keyplayer nodes 15 and 32, we quickly realize that node 15 has a much higher score than 32. In addition, other nodes that aren’t considered keyplayers also have higher scores.

#kpcent reports the group-level centrality scores.
kpcent(g11_ajd, 15, type = "degree", binary = TRUE) #for 15
## [1] 96
kpcent(g11_ajd, 32, type = "degree", binary = TRUE) #for 32
## [1] 8
kpcent(g11_ajd,c(15,32),type="degree") #for both together
## [1] 102

Thus, we want to confirm these keyplayers through another diffusion function.

Diffusion

Now, we wanted to compare the diffusion level of the same network with another function. Diffusion measures player’s ability to disseminate information through all the possible paths. For each path from i to j there is a reaching probability P(ij), which is specified in the inputted adjacency matrix (g11_ajd).

From both algorithms, we can see that we obtain two similar results, as both functions determine Vernon Dursley as the character with the highest diffusion. However, Remus Lupin is not considered a key player for diffusion in the following function.

[We are going to test these results in Netlogo]

keys_diffusion<-keys
keys_diffusion$Gender_Male<-NULL
keys_diffusion$Color<-NULL
keys_diffusion$id<-NULL

keys_diffusion$diffusion<-diffusion(g11_ajd, c(1:65), T = ncol(g11_ajd))

head(keys_diffusion[order(-keys_diffusion$diffusion),], n=65 )
##                 Character Alignment       House    diffusion
## 15         Vernon Dursley   Neutral      Muggle 4.977681e+80
## 25            Viktor Krum      Good  Durmstrang 4.542946e+80
## 8    Bartemius Crouch Jr.      Evil        <NA> 4.310119e+80
## 6          Vincent Crabbe      Evil   Slytherin 4.030147e+80
## 5      Vincent Crabbe Sr.      Evil   Slytherin 4.009859e+80
## 2            Sirius Black      Good  Gryffindor 3.382735e+80
## 23          Rubeus Hagrid      Good  Gryffindor 3.107142e+80
## 21          Gregory Goyle      Evil   Slytherin 3.071350e+80
## 22       Hermione Granger      Good  Gryffindor 3.071350e+80
## 24         Igor Karkaroff   Neutral  Durmstrang 2.946502e+80
## 20              Goyle Sr.      Evil   Slytherin 2.587286e+80
## 14        Petunia Dursley   Neutral      Muggle 2.552084e+80
## 43      Quirinus Quirrell      Evil   Ravenclaw 2.461041e+80
## 18         Nicolas Flamel      Good Beauxbatons 2.459118e+80
## 53        Charlie Weasley      Good  Gryffindor 2.368910e+80
## 7    Bartemius Crouch Sr.      Good        <NA> 2.275109e+80
## 9          Fleur Delacour      Good Beauxbatons 2.137745e+80
## 12       Albus Dumbledore      Good  Gryffindor 1.998798e+80
## 50 Dolores Janes Umbridge      Evil   Slytherin 1.970880e+80
## 13         Dudley Dursley   Neutral      Muggle 1.965585e+80
## 4               Cho Chang      Good   Ravenclaw 1.810983e+80
## 39        Peter Pettigrew      Evil  Gryffindor 1.705356e+80
## 10         Cedric Diggory      Good  Hufflepuff 1.691566e+80
## 40           Harry Potter      Good  Gryffindor 1.679720e+80
## 28       Frank Longbottom      Good  Gryffindor 1.667300e+80
## 16            Argus Filch   Neutral       Squib 1.435114e+80
## 37     Minerva McGonagall      Good  Gryffindor 1.403734e+80
## 36          Olympe Maxime      Good Beauxbatons 1.402095e+80
## 17        Seamus Finnigan      Good  Gryffindor 1.364358e+80
## 27       Alice Longbottom      Good  Gryffindor 1.247948e+80
## 29     Neville Longbottom      Good  Gryffindor 1.241279e+80
## 35        Narcissa Malfoy      Evil   Slytherin 1.236057e+80
## 34          Lucius Malfoy      Evil   Slytherin 1.189814e+80
## 45            Mary Riddle      Good      Muggle 1.141611e+80
## 44         Tom Riddle Sr.      Evil      Muggle 1.102753e+80
## 31   Xenophilius Lovegood      Good   Ravenclaw 1.074551e+80
## 51         Arthur Weasley      Good  Gryffindor 1.005567e+80
## 55         George Weasley      Good  Gryffindor 9.750868e+79
## 49       Nymphadora Tonks      Good  Hufflepuff 9.513838e+79
## 56          Ginny Weasley      Good  Gryffindor 9.169994e+79
## 57          Molly Weasley      Good  Gryffindor 9.169994e+79
## 58          Percy Weasley      Good  Gryffindor 9.169994e+79
## 3          Lavender Brown      Good  Gryffindor 8.578294e+79
## 11   Aberforth Dumbledore      Good  Gryffindor 7.039974e+79
## 41           James Potter      Good  Gryffindor 6.914750e+79
## 26    Bellatrix Lestrange      Evil   Slytherin 6.829383e+79
## 46         Lord Voldemort      Evil   Slytherin 6.637112e+79
## 19        Cornelius Fudge   Neutral        <NA> 6.581592e+79
## 30          Luna Lovegood      Good   Ravenclaw 6.337262e+79
## 47           Rita Skeeter      Good        <NA> 5.888776e+79
## 1  Regulus Arcturus Black      Good   Slytherin 5.838832e+79
## 52           Bill Weasley      Good  Gryffindor 5.227420e+79
## 54           Fred Weasley      Good  Gryffindor 4.759289e+79
## 42            Lily Potter      Good  Gryffindor 4.639607e+79
## 33           Draco Malfoy      Evil   Slytherin 3.515288e+79
## 60                  Dobby      Good        <NA> 3.362040e+79
## 38          Alastor Moody      Good        <NA> 3.141697e+79
## 62                 Hedwig      Good        <NA> 2.888647e+79
## 63         Moaning Myrtle      Good   Ravenclaw 2.888647e+79
## 32            Remus Lupin      Good  Gryffindor 2.484401e+79
## 64                 Aragog   Neutral        <NA> 2.470360e+79
## 65                  Grawp      Good        <NA> 2.470360e+79
## 48          Severus Snape      Good   Slytherin 2.338774e+79
## 59            Ron Weasley      Good  Gryffindor 1.162673e+79
## 61                 Fluffy      Good        <NA> 5.658621e+78

Community Detection

Subgroups and commmunities

Subgroup discovery aims at identifying interesting descriptive subgroups contained in a dataset - from a compositional network analysis view, aiming at a description given by a set of attribute values.

The following functions for cliques give us:

  • The list of all cliques (groups of nodes) within the network
  • The size of all the cliques
  • The largest or all the maximal cliques in an undirected graph

In this case, we have two maximal cliques, which differ very slightly (Arthur Weasley and Voldemort are interchanged). This could be because they are within the limits of being included in the clique. Thus, taking them out of the cliques would not have such a great impact.

sapply(cliques(g11), length) #clique sizes
##    [1]  1  1  1  1  1  1  1  1  1  1  1  1  2  2  2  1  2  1  2  1  2  1  2
##   [24]  2  1  2  1  2  1  2  1  2  1  2  1  2  1  2  1  2  1  2  1  2  3  2
##   [47]  3  2  3  2  3  3  2  2  1  2  3  2  2  1  2  3  2  3  2  2  2  1  2
##   [70]  2  1  2  3  2  3  2  1  2  3  2  1  2  3  4  3  4  3  2  3  4  3  2
##   [93]  3  4  3  4  3  2  3  2  3  2  3  2  3  3  2  3  2  3  3  2  2  2  2
##  [116]  1  2  3  4  3  4  4  3  3  2  3  2  3  2  3  3  2  2  2  1  2  3  4
##  [139]  3  2  3  4  3  2  3  2  1  2  3  4  3  2  2  3  2  1  2  3  4  3  2
##  [162]  3  2  1  2  3  4  3  2  3  2  1  2  3  4  3  2  3  2  1  2  3  4  3
##  [185]  2  3  2  1  2  2  2  2  1  2  3  4  5  4  3  3  4  3  2  3  4  5  4
##  [208]  5  4  3  4  3  4  3  3  2  3  4  5  4  3  4  5  4  5  4  3  4  3  4
##  [231]  3  4  3  2  3  2  2  3  4  3  3  3  2  3  4  3  3  2  3  4  3  4  3
##  [254]  4  3  2  3  2  3  2  3  2  3  2  3  2  3  2  3  2  2  2  2  2  2  1
##  [277]  2  3  4  5  4  3  4  3  2  3  4  3  2  3  2  1  2  3  4  5  4  3  4
##  [300]  4  3  4  4  3  3  2  3  4  3  4  3  2  3  4  3  2  3  3  2  3  3  2
##  [323]  2  1  2  3  4  5  4  3  4  3  2  3  4  3  4  3  2  3  2  3  2  2  1
##  [346]  2  3  4  5  5  4  4  3  4  4  3  3  2  3  4  4  3  3  2  3  3  2  2
##  [369]  1  2  3  4  5  4  3  4  3  2  3  4  3  2  3  2  2  1  2  3  4  5  4
##  [392]  3  4  3  2  3  4  5  4  3  4  3  2  3  4  3  2  3  2  1  2  3  4  5
##  [415]  6  5  4  5  4  3  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6  5  4
##  [438]  5  4  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  6  5  4  5  4  5
##  [461]  4  3  4  5  4  4  3  4  5  4  4  3  4  5  4  3  3  4  3  4  3  3  3
##  [484]  2  3  4  5  4  3  4  5  4  3  4  3  4  3  2  3  4  3  3  2  3  4  3
##  [507]  3  2  3  4  3  2  2  3  2  3  2  2  2  1  2  3  4  5  6  5  4  5  5
##  [530]  4  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  5  4  5  4  3  4  5
##  [553]  4  3  4  3  2  3  4  5  4  3  4  4  3  3  2  3  4  3  2  3  3  2  2
##  [576]  1  2  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6  5
##  [599]  4  5  4  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  2  3  4
##  [622]  5  4  3  4  3  2  3  4  5  4  3  4  3  2  3  4  5  4  3  4  3  2  3
##  [645]  4  5  4  3  4  3  2  3  4  5  4  3  4  3  3  2  3  4  3  2  3  2  2
##  [668]  1  2  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  4  3  4  5  4  3
##  [691]  4  3  2  3  4  5  4  3  4  3  4  3  2  3  4  3  2  3  2  3  2  1  2
##  [714]  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5  4  3  4  3
##  [737]  2  3  4  5  4  3  4  5  4  3  4  3  2  3  4  5  4  3  4  3  2  3  4
##  [760]  3  3  2  3  4  3  2  3  2  2  1  2  3  4  5  6  5  4  5  4  3  4  5
##  [783]  4  3  4  3  2  3  4  5  4  3  4  3  2  3  4  3  2  3  2  2  1  2  3
##  [806]  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  4
##  [829]  3  4  3  4  5  4  3  4  3  2  3  4  5  4  3  4  3  2  3  2  3  4  3
##  [852]  2  3  2  1  2  3  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5
##  [875]  4  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5
##  [898]  4  5  5  4  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  7  6  5  6
##  [921]  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  5  4  5
##  [944]  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  4  3  4  5  4  3  4
##  [967]  5  4  3  4  3  2  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  5  4
##  [990]  4  3  4  5  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  5  4  5  4
## [1013]  3  4  5  4  3  4  5  4  3  4  3  2  3  4  5  4  3  4  4  3  3  2  3
## [1036]  4  3  2  3  4  3  2  3  3  2  2  1  2  3  4  5  6  7  6  5  6  5  4
## [1059]  5  6  5  4  5  4  3  4  5  6  7  6  5  6  7  6  5  6  5  6  5  4  5
## [1082]  6  5  4  5  6  5  4  5  4  5  4  3  4  5  6  5  4  5  6  5  4  5  4
## [1105]  5  4  3  4  5  4  3  4  5  4  3  4  3  4  3  2  3  4  5  6  5  4  5
## [1128]  4  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  6  5  4  5  4  5  4
## [1151]  3  4  5  4  3  4  5  4  5  4  3  4  3  4  3  4  3  3  2  3  4  5  4
## [1174]  3  4  5  4  3  4  3  4  3  2  3  4  3  2  3  4  3  4  3  2  3  2  3
## [1197]  2  3  2  2  1  2  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3
## [1220]  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  4
## [1243]  3  4  5  4  3  4  3  2  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5
## [1266]  4  3  4  5  6  7  6  5  6  5  6  5  4  5  6  5  4  5  4  5  4  3  4
## [1289]  5  6  5  4  5  4  5  4  3  4  5  4  3  4  3  4  3  2  3  4  5  6  5
## [1312]  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  4  5  4  3  4
## [1335]  5  4  5  4  3  4  3  4  3  4  3  3  2  3  4  5  4  3  4  3  4  3  2
## [1358]  3  4  3  4  3  2  3  2  3  2  3  2  2  1  2  3  4  5  6  7  6  5  6
## [1381]  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3
## [1404]  2  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6
## [1427]  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  4  3  4  5  4  3
## [1450]  4  3  2  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6
## [1473]  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5
## [1496]  6  5  4  5  6  5  4  5  4  3  4  5  4  3  4  5  4  3  4  3  2  3  4
## [1519]  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  6  5
## [1542]  4  5  4  3  4  5  4  3  4  5  4  5  4  3  4  3  4  3  2  3  4  5  4
## [1565]  3  4  5  4  3  4  3  2  3  4  3  2  3  4  3  4  3  2  3  2  3  2  1
## [1588]  2  3  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6
## [1611]  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  5  4  5  6  5
## [1634]  4  5  4  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6
## [1657]  7  8  7  6  7  8  7  6  7  6  5  6  7  6  5  6  7  6  5  6  5  4  5
## [1680]  6  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4
## [1703]  5  6  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3
## [1726]  4  5  6  5  4  5  6  5  4  5  4  3  4  5  4  3  4  5  4  3  4  3  2
## [1749]  3  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5
## [1772]  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5
## [1795]  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  8  7  6  7  6  5  6  7
## [1818]  6  5  6  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6
## [1841]  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  4  3  4  5
## [1864]  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  6
## [1887]  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  5  4  4  3  4  5
## [1910]  4  3  4  4  3  3  2  3  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4
## [1933]  5  5  4  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5
## [1956]  6  5  4  5  5  4  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  7  6
## [1979]  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  7  6  5  6  5
## [2002]  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  6  5  4  5  4
## [2025]  3  4  5  4  3  4  5  4  3  4  3  2  3  4  5  4  3  4  3  2  3  4  5
## [2048]  4  3  4  3  2  3  4  5  6  5  4  5  5  4  4  3  4  5  4  3  4  4  3
## [2071]  3  2  3  4  5  6  5  4  5  6  5  4  5  4  3  4  5  4  3  4  5  4  3
## [2094]  4  3  2  3  4  5  4  3  4  5  4  3  4  4  3  3  2  3  4  3  2  3  4
## [2117]  3  2  3  3  2  2  1  2  3  4  5  6  5  4  5  6  7  6  7  6  5  6  5
## [2140]  6  5  4  5  6  5  6  5  4  5  4  5  4  3  4  5  4  3  4  5  6  5  6
## [2163]  5  4  5  4  5  4  3  4  5  4  5  4  3  4  3  4  3  2  3  4  5  4  3
## [2186]  4  5  6  5  6  5  4  5  4  5  4  3  4  5  4  5  4  3  4  3  4  3  2
## [2209]  3  4  3  2  3  4  5  4  5  4  3  4  3  4  3  2  3  4  3  4  3  2  3
## [2232]  2  3  2  1  2  3  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4
## [2255]  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  5
## [2278]  4  5  6  5  4  5  4  3  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6
## [2301]  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5
## [2324]  4  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6  7  6
## [2347]  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  5  4  5  6  5
## [2370]  4  5  4  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5  4
## [2393]  3  4  3  2  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5
## [2416]  6  5  4  5  4  3  4  5  4  5  4  3  4  3  4  3  2  3  4  5  4  3  4
## [2439]  3  2  3  4  3  4  3  2  3  2  3  2  1  2  3  4  5  6  7  6  5  6  7
## [2462]  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  4  3  4  5  6
## [2485]  5  4  5  6  5  4  5  4  3  4  5  4  3  4  5  4  3  4  3  2  3  4  5
## [2508]  6  5  4  5  6  5  5  4  4  5  4  4  4  3  4  5  4  3  4  5  4  4  3
## [2531]  3  4  3  3  3  2  3  4  3  2  3  4  5  4  3  4  5  4  4  4  3  4  3
## [2554]  4  3  3  3  3  2  3  4  5  4  3  4  3  2  3  4  3  2  3  4  3  3  3
## [2577]  2  3  2  3  2  2  2  2  1  2  3  4  5  6  7  8  9  8  7  8  7  6  7
## [2600]  8  7  6  7  6  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6
## [2623]  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  5  4  5
## [2646]  6  5  4  5  4  3  4  5  6  7  8  9  8  7  8  9  8  7  8  7  6  7  8
## [2669]  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  8  7  6  7  6  5  6  7
## [2692]  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  8  7  6  7  6  5  6
## [2715]  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  7  6  5  6  5  4  5
## [2738]  6  5  4  5  6  5  4  5  4  3  4  5  6  7  8  9  8  7  8  8  7  7  6
## [2761]  7  8  7  6  7  7  6  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7
## [2784]  6  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6
## [2807]  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  9  8  7  8  7
## [2830]  6  7  8  7  6  7  6  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4
## [2853]  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7
## [2876]  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4
## [2899]  5  6  5  4  5  5  4  4  3  4  5  6  7  8  7  6  7  7  6  6  5  6  7
## [2922]  6  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4
## [2945]  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7
## [2968]  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  8  7  6
## [2991]  7  6  5  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  7  6  5
## [3014]  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  6  5
## [3037]  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  6  5  6  7  6  5  6  5
## [3060]  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  6  5  4  5  5
## [3083]  4  4  3  4  5  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  7  8  7
## [3106]  6  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  6  5  6  7  6
## [3129]  5  6  5  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7
## [3152]  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  5  4  5  6
## [3175]  5  4  5  4  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5
## [3198]  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  8
## [3221]  7  6  7  6  5  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  7
## [3244]  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6
## [3267]  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  7  6  5  6  5  4  5
## [3290]  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  6  5  4  5  4  3  4
## [3313]  5  4  3  4  5  4  3  4  3  2  3  4  5  6  7  8  7  6  7  7  6  6  5
## [3336]  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6
## [3359]  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5
## [3382]  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  6
## [3405]  5  6  7  6  5  6  5  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3
## [3428]  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6
## [3451]  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  5  4  4  3
## [3474]  4  5  4  3  4  4  3  3  2  3  4  5  6  7  6  5  6  6  5  5  4  5  6
## [3497]  5  4  5  5  4  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3
## [3520]  4  5  6  5  4  5  5  4  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6
## [3543]  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  5  4  5
## [3566]  6  5  4  5  4  3  4  5  6  7  6  5  6  7  6  5  6  5  4  5  6  5  4
## [3589]  5  6  5  4  5  4  3  4  5  6  5  4  5  6  5  4  5  4  3  4  5  4  3
## [3612]  4  5  4  3  4  3  2  3  4  5  6  5  4  5  5  4  4  3  4  5  4  3  4
## [3635]  4  3  3  2  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3  4  5
## [3658]  6  5  4  5  6  5  4  5  4  3  4  5  4  3  4  5  4  3  4  3  2  3  4
## [3681]  5  4  3  4  5  4  3  4  4  3  3  2  3  4  3  2  3  4  3  2  3  3  2
## [3704]  2  1  2  3  4  5  6  7  8  9 10  9  8  9  8  7  8  9  8  7  8  7  6
## [3727]  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  9  8  7  8  7
## [3750]  6  7  8  7  6  7  6  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4
## [3773]  5  6  7  8  9 10  9  8  9 10  9  8  9  8  7  8  9  8  7  8  9  8  7
## [3796]  8  7  6  7  8  9  8  7  8  9  8  7  8  7  6  7  8  7  6  7  8  7  6
## [3819]  7  6  5  6  7  8  9  8  7  8  9  8  7  8  7  6  7  8  7  6  7  8  7
## [3842]  6  7  6  5  6  7  8  7  6  7  8  7  6  7  6  5  6  7  6  5  6  7  6
## [3865]  5  6  5  4  5  6  7  8  9 10  9  8  9  9  8  8  7  8  9  8  7  8  8
## [3888]  7  7  6  7  8  9 10  9  8  9  8  7  8  9  8  7  8  7  6  7  8  9  8
## [3911]  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9 10  9  8  9
## [3934]  8  7  8  9  8  7  8  7  6  7  8  9 10  9  8  9  8  7  8  9  8  7  8
## [3957]  7  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  9  8  7
## [3980]  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9  8  7  8  7  6
## [4003]  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6
## [4026]  5  5  4  5  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6
## [4049]  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7
## [4072]  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  9  8  7  8  7  6
## [4095]  7  8  7  6  7  6  5  6  7  8  9  8  7  8  9  8  7  8  7  6  7  8  7
## [4118]  6  7  8  7  6  7  6  5  6  7  8  7  6  7  8  7  6  7  6  5  6  7  6
## [4141]  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5
## [4164]  6  6  5  5  4  5  6  7  8  7  6  7  8  7  6  7  6  5  6  7  6  5  6
## [4187]  7  6  5  6  5  4  5  6  7  6  5  6  7  6  5  6  6  5  5  4  5  6  5
## [4210]  4  5  6  5  4  5  5  4  4  3  4  5  6  7  8  9  8  7  8  7  6  7  8
## [4233]  7  6  7  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7
## [4256]  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  6  5  6
## [4279]  7  6  5  6  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5
## [4302]  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  8  9  8  7  8
## [4325]  7  6  7  8  7  6  7  6  5  6  7  8  9  8  7  8  9  8  7  8  7  6  7
## [4348]  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  8  7  6  7  6  5  6
## [4371]  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5
## [4394]  6  5  4  5  6  7  8  7  6  7  8  7  6  7  6  5  6  7  6  5  6  7  6
## [4417]  5  6  5  4  5  6  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5
## [4440]  4  5  4  3  4  5  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7
## [4463]  6  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7
## [4486]  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  9  8  7  8
## [4509]  7  6  7  8  7  6  7  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7
## [4532]  6  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6
## [4555]  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5
## [4578]  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5
## [4601]  4  4  3  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5
## [4624]  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6
## [4647]  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  8  7  6  7  6  5
## [4670]  6  7  6  5  6  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4
## [4693]  5  6  7  8  7  6  7  8  7  6  7  6  5  6  7  6  5  6  7  6  5  6  5
## [4716]  4  5  6  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4
## [4739]  3  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5
## [4762]  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  7  6
## [4785]  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  6  5
## [4808]  4  5  5  4  4  3  4  5  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6
## [4831]  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  6  5
## [4854]  6  7  6  5  6  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4
## [4877]  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  8  9  8  7
## [4900]  8  9  8  7  8  7  6  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6
## [4923]  7  8  7  6  7  6  5  6  7  6  5  6  7  6  5  6  5  4  5  6  7  8  7
## [4946]  6  7  8  7  6  7  6  5  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6
## [4969]  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7
## [4992]  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9  8
## [5015]  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6  6  5  6  7
## [5038]  6  5  6  6  5  5  4  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6
## [5061]  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7
## [5084]  6  5  6  7  6  5  6  5  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6
## [5107]  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5
## [5130]  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  8
## [5153]  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7
## [5176]  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4
## [5199]  5  5  4  4  3  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5
## [5222]  6  7  8  7  6  7  8  7  6  7  6  5  6  7  6  5  6  7  6  5  6  5  4
## [5245]  5  6  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3
## [5268]  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6
## [5291]  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5
## [5314]  6  5  4  5  6  5  4  5  5  4  4  3  4  5  4  3  4  5  4  3  4  4  3
## [5337]  3  2  3  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7
## [5360]  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  5  4  5  6
## [5383]  5  4  5  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5
## [5406]  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  4  3  4
## [5429]  5  4  3  4  3  2  3  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5
## [5452]  4  5  6  7  8  7  6  7  8  7  6  7  6  5  6  7  6  5  6  7  6  5  6
## [5475]  5  4  5  6  7  6  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5
## [5498]  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6
## [5521]  5  6  7  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5
## [5544]  4  5  6  5  4  5  4  3  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6
## [5567]  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7
## [5590]  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6
## [5613]  5  4  5  5  4  4  3  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5
## [5636]  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6
## [5659]  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  6  5  5  4  5  6  5
## [5682]  4  5  5  4  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4
## [5705]  5  6  5  4  5  5  4  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  7
## [5728]  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  6  5  6
## [5751]  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  5  4  4  3  4  5  4  3
## [5774]  4  4  3  3  2  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4
## [5797]  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  7  6  5  6  7
## [5820]  6  5  6  5  4  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  6
## [5843]  5  4  5  4  3  4  5  4  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5
## [5866]  5  4  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  5  4  5  4  3  4
## [5889]  5  4  3  4  3  2  3  4  5  6  5  4  5  6  5  4  5  4  3  4  5  4  3
## [5912]  4  5  4  3  4  3  2  3  4  5  4  3  4  5  4  3  4  4  3  3  2  3  4
## [5935]  3  2  3  4  3  2  3  3  2  2  1  2  3  4  5  6  7  8  9 10 11 10  9
## [5958] 10 10  9  9  8  9 10  9  8  9  9  8  8  7  8  9 10 11 10  9 10  9  8
## [5981]  9 10  9  8  9  8  7  8  9 10  9  8  9  9  8  8  7  8  9  8  7  8  8
## [6004]  7  7  6  7  8  9 10  9  8  9  9  8  8  7  8  9  8  7  8  8  7  7  6
## [6027]  7  8  9 10  9  8  9  8  7  8  9  8  7  8  7  6  7  8  9  8  7  8  8
## [6050]  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9 10  9  8  9  9  8  8
## [6073]  7  8  9  8  7  8  8  7  7  6  7  8  9 10  9  8  9  8  7  8  9  8  7
## [6096]  8  7  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6
## [6119]  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9
## [6142]  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6  6  5  6
## [6165]  7  6  5  6  6  5  5  4  5  6  7  8  9 10  9  8  9  9  8  8  7  8  9
## [6188]  8  7  8  8  7  7  6  7  8  9 10  9  8  9  8  7  8  9  8  7  8  7  6
## [6211]  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9
## [6234]  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9  8  7  8
## [6257]  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5
## [6280]  6  6  5  5  4  5  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7
## [6303]  6  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7
## [6326]  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  7
## [6349]  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5  6  7
## [6372]  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4
## [6395]  3  4  5  6  7  8  9 10  9  8  9  9  8  8  7  8  9  8  7  8  8  7  7
## [6418]  6  7  8  9 10  9  8  9  8  7  8  9  8  7  8  7  6  7  8  9  8  7  8
## [6441]  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9  8  7  8  8  7  7
## [6464]  6  7  8  7  6  7  7  6  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6
## [6487]  7  6  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5
## [6510]  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8
## [6533]  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6  6  5
## [6556]  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6
## [6579]  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5
## [6602]  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  8
## [6625]  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7  8  9  8  7
## [6648]  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6  6  5  6  7  6
## [6671]  5  6  6  5  5  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6
## [6694]  5  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6
## [6717]  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  8  7  6  7
## [6740]  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5  6
## [6763]  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4
## [6786]  4  3  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4
## [6809]  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  5  4
## [6832]  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  7  8  9 10  9  8  9  9
## [6855]  8  8  7  8  9  8  7  8  8  7  7  6  7  8  9 10  9  8  9  8  7  8  9
## [6878]  8  7  8  7  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6
## [6901]  5  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6  7
## [6924]  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6  6
## [6947]  5  6  7  6  5  6  6  5  5  4  5  6  7  8  9  8  7  8  8  7  7  6  7
## [6970]  8  7  6  7  7  6  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6
## [6993]  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7
## [7016]  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6
## [7039]  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5
## [7062]  4  5  5  4  4  3  4  5  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6
## [7085]  7  7  6  6  5  6  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7
## [7108]  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6
## [7131]  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5
## [7154]  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5
## [7177]  4  4  3  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5
## [7200]  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6
## [7223]  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  6  5  6  6  5  5
## [7246]  4  5  6  5  4  5  5  4  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4
## [7269]  5  4  3  4  5  6  5  4  5  5  4  4  3  4  5  4  3  4  4  3  3  2  3
## [7292]  4  5  6  7  8  9  8  7  8  8  7  7  6  7  8  7  6  7  7  6  6  5  6
## [7315]  7  8  9  8  7  8  7  6  7  8  7  6  7  6  5  6  7  8  7  6  7  7  6
## [7338]  6  5  6  7  6  5  6  6  5  5  4  5  6  7  6  5  6  5  4  5  6  7  8
## [7361]  7  6  7  7  6  6  5  6  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7
## [7384]  6  5  6  7  6  5  6  5  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4
## [7407]  5  5  4  4  3  4  5  6  7  8  7  6  7  7  6  6  5  6  7  6  5  6  6
## [7430]  5  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5  4  5  6  7  6
## [7453]  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  5  4  5  4  3
## [7476]  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6
## [7499]  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4  5  5  4  4  3
## [7522]  4  5  4  3  4  4  3  3  2  3  4  5  6  7  8  7  6  7  7  6  6  5  6
## [7545]  7  6  5  6  6  5  5  4  5  6  7  8  7  6  7  6  5  6  7  6  5  6  5
## [7568]  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6
## [7591]  5  4  5  4  3  4  5  6  7  6  5  6  6  5  5  4  5  6  5  4  5  5  4
## [7614]  4  3  4  5  6  7  6  5  6  5  4  5  6  5  4  5  4  3  4  5  6  5  4
## [7637]  5  5  4  4  3  4  5  4  3  4  4  3  3  2  3  4  5  6  7  6  5  6  6
## [7660]  5  5  4  5  6  5  4  5  5  4  4  3  4  5  6  7  6  5  6  5  4  5  6
## [7683]  5  4  5  4  3  4  5  6  5  4  5  5  4  4  3  4  5  4  3  4  4  3  3
## [7706]  2  3  4  5  4  3  4  3  2  3  4  5  6  5  4  5  5  4  4  3  4  5  4
## [7729]  3  4  4  3  3  2  3  4  5  6  5  4  5  4  3  4  5  4  3  4  3  2  3
## [7752]  4  5  4  3  4  4  3  3  2  3  4  3  2  3  3  2  2
largest_cliques(g11) # cliques with max number of nodes
## [[1]]
## + 11/65 vertices, named, from 861146a:
##  [1] Harry Potter     Hermione Granger Ron Weasley      Albus Dumbledore
##  [5] Arthur Weasley   Molly Weasley    Fred Weasley     George Weasley  
##  [9] Ginny Weasley    Bill Weasley     Charlie Weasley 
## 
## [[2]]
## + 11/65 vertices, named, from 861146a:
##  [1] Harry Potter     Hermione Granger Ron Weasley      Albus Dumbledore
##  [5] Lord Voldemort   Charlie Weasley  Bill Weasley     Fred Weasley    
##  [9] George Weasley   Ginny Weasley    Molly Weasley

From this plot, we can see that the biggest clique makes sense because it is composed of the Weasley family members as well as Ron Weasley’s best friends (Harry and Hermione) and their worst enemy (Voldemort). This implies, that without any of these characters, there wouldn’t be a story line. More importantly, the clique would probably break if Ron died because he’s the most important link in the clique (between the friends and the family).

#layout of the RMarkdown
par(mar=c(1,1,3,1))

#identifying the nodes within the network which belong to the clique
vcol <- rep("grey80", vcount(g11))
vcol[unlist(largest_cliques(g11))] <- "gold"

plot(g11,
     layout = mylayout,
     vertex.label = V(g11)$name,
     vertex.color=vcol, 
     vertex.label.cex = 0.6,
     vertex.label.dist=6,
     vertex.size = 25,
     asp = 0.75,
     rescale = FALSE,
     ylim = c(-5,4.5),
     xlim = c(-2,2))
legend("top", legend = "", cex = 1.0, bty = "n", ncol = 1,
       title = "Harry Potter - Largest Clique")

We can also analyze dyads (pairs of two nodes), triads (groups of three nodes) and bigger cliques in our network. For dyads, we can use the function dyad_census() from igraph or dyad.census() from sna. Both are identical and calculate a Holland and Leinhardt dyad census.

mut: 330 pairs with mutual connections. asym: 0 pairs with non-mutual connections (in the undirected network, there are none). null: 1750 pairs with no connection between them.

Thus, from our network, there are an additional 1750 pairs of relationships possible within the nodes. This goes to support that only certain characters have high degree centralities that connect to other characters.

adjacency <- as.matrix(as_adjacency_matrix(g11))
sna::dyad.census(adjacency)
##      Mut Asym Null
## [1,] 330    0 1750

“A (maximal) clique is a maximal set of mutually adjacency vertices.”

In this case, we wanted an overall view on the rest of the cliques. In order words, we wanted to see the frequence distribution of the cliques based on the number of edges.

node_clique <- clique.census(adjacency, mode = "graph", tabulate.by.vertex = TRUE, clique.comembership = "sum")
edge_clique <- clique.census(adjacency, mode = "graph", tabulate.by.vertex = FALSE, clique.comembership = "sum")
edge_clique$clique.count
##  1  2  3  4  5  6  7  8  9 10 11 
##  0 13 12 14 22  9 13  2  2  6  2

Community Detection

Clusters (Community detection based on edge betweenness (Newman-Girvan))

The Girvan-Newman algorithm detects communities by progressively removing edges from the original network. The connected components of the remaining network are the communities. Instead of trying to construct a measure that tells us which edges are the most central to communities, the Girvan-Newman algorithm focuses on edges that are most likely “between” communities.

From this network, the algorithm creates 13 communities.

#this is a list of all the cluster groups within the network
ceb <- cluster_edge_betweenness(g11)
ceb
## IGRAPH clustering edge betweenness, groups: 13, mod: 0.041
## + groups:
##   $`1`
##    [1] "Regulus Arcturus Black" "Sirius Black"          
##    [3] "Lavender Brown"         "Cho Chang"             
##    [5] "Vincent Crabbe Sr."     "Vincent Crabbe"        
##    [7] "Bartemius Crouch Jr."   "Fleur Delacour"        
##    [9] "Aberforth Dumbledore"   "Albus Dumbledore"      
##   [11] "Argus Filch"            "Seamus Finnigan"       
##   [13] "Cornelius Fudge"        "Gregory Goyle"         
##   [15] "Hermione Granger"       "Rubeus Hagrid"         
##   [17] "Bellatrix Lestrange"    "Neville Longbottom"    
##   + ... omitted several groups/vertices
length(ceb) #number of communities
## [1] 13
membership(ceb) #community membership for each node - verify that each node was attributed a community
## Regulus Arcturus Black           Sirius Black         Lavender Brown 
##                      1                      1                      1 
##              Cho Chang     Vincent Crabbe Sr.         Vincent Crabbe 
##                      1                      1                      1 
##   Bartemius Crouch Sr.   Bartemius Crouch Jr.         Fleur Delacour 
##                      2                      1                      1 
##         Cedric Diggory   Aberforth Dumbledore       Albus Dumbledore 
##                      3                      1                      1 
##         Dudley Dursley        Petunia Dursley         Vernon Dursley 
##                      4                      4                      4 
##            Argus Filch        Seamus Finnigan         Nicolas Flamel 
##                      1                      1                      5 
##        Cornelius Fudge              Goyle Sr.          Gregory Goyle 
##                      1                      6                      1 
##       Hermione Granger          Rubeus Hagrid         Igor Karkaroff 
##                      1                      1                      7 
##            Viktor Krum    Bellatrix Lestrange       Alice Longbottom 
##                      3                      1                      8 
##       Frank Longbottom     Neville Longbottom          Luna Lovegood 
##                      8                      1                      1 
##   Xenophilius Lovegood            Remus Lupin           Draco Malfoy 
##                      9                      1                      1 
##          Lucius Malfoy        Narcissa Malfoy          Olympe Maxime 
##                      1                      1                      7 
##     Minerva McGonagall          Alastor Moody        Peter Pettigrew 
##                      1                      1                      1 
##           Harry Potter           James Potter            Lily Potter 
##                      1                      1                      1 
##      Quirinus Quirrell         Tom Riddle Sr.            Mary Riddle 
##                      1                     10                     10 
##         Lord Voldemort           Rita Skeeter          Severus Snape 
##                      1                     11                      1 
##       Nymphadora Tonks Dolores Janes Umbridge         Arthur Weasley 
##                      1                      1                      1 
##           Bill Weasley        Charlie Weasley           Fred Weasley 
##                      1                      1                      1 
##         George Weasley          Ginny Weasley          Molly Weasley 
##                      1                      1                      1 
##          Percy Weasley            Ron Weasley                  Dobby 
##                      1                      1                      1 
##                 Fluffy                 Hedwig         Moaning Myrtle 
##                      1                     12                     13 
##                 Aragog                  Grawp 
##                      1                      1

High modularity for a partitioning reflects dense connections within communities and sparse connections across communities. with this first algorithm, we calculated a low modularity of 0.04 because it creates the communites only based on the betweenness of the nodes.

modularity(ceb) # score of the graph partitioning 
## [1] 0.04138659

When plotting the clusters, we obtain:

#layout of the RMarkdown
par(mar=c(1,1,3,1))

plot(ceb,
     g11,
     layout = mylayout,
     vertex.label = NA)

Community detection based on greedy optimization of modularity

After calculating a very low modularity with the cmmunity detection based on edge betweenness, we decided to create another community model based on greedy optimization, which is also the optimization of the modularity itself.

The aim of modularity-optimizing community detection algorithms is to determine the partition(s) with maximum modularity. However, because we are looking for a maximum over all partitions of a network, the number of which is exponential in N, maximising modularity is equivalent to comparing the modularity of each and every partition of the network to determine the best one.

From this algorithm, we were able to increase our modularity score to 0.23

When looking at our restult, it is a greedy community analysis algorithm that optimises the modularity score. This method starts with a totally non-clustered initial assignment, where each node forms a singleton community, and then computes the expected improvement of modularity for each pair of communities, chooses a community pair that gives the maximum improvement of modularity and merges them into a new community. The above procedure is repeated until no community pairs merge leads to an increase in modularity“.

cfg <- cluster_fast_greedy(g11)

modularity(cfg)
## [1] 0.2334389

When plotting the clusters, we obtain:

par(mar=c(0,0,0,0))

V(g11)$community <- cfg$membership

colrs <- adjustcolor( c("gray50", "tomato", "gold", "yellowgreen"), alpha=.6)

plot(g11,
     layout = mylayout,
     vertex.label = V(g11)$name,
     vertex.color=colrs[V(g11)$community], 
     vertex.label.color = "black",
     vertex.label.cex = 0.6,
     vertex.label.dist=3,
     vertex.size = 20,
     legend = TRUE,
     asp = 0.75,
     rescale = FALSE,
     ylim = c(-4.5,5),
     xlim = c(-3,2))
legend("top", legend = "", cex = 2, bty = "n", ncol = 1,
       title = "Harry Potter - Communities")

When wanting to have a more descriptive view of the dataset, we created a data frame to see which nodes belong to which community.

fg_HP<-fastgreedy.community(igraph::simplify(g1,edge.attr.comb = "min"))
keys_community<-keys
keys_community$grouping<-as.factor(membership(fg_HP))
keys_community$Gender_Male<-NULL
keys_community$Color<-NULL

head(keys_community[order(-keys_community$grouping),])
## Warning in Ops.factor(keys_community$grouping): '-' not meaningful for
## factors
##                Character Alignment      House grouping
## 1 Regulus Arcturus Black      Good  Slytherin        1
## 2           Sirius Black      Good Gryffindor        2
## 3         Lavender Brown      Good Gryffindor        4
## 4              Cho Chang      Good  Ravenclaw        4
## 5     Vincent Crabbe Sr.      Evil  Slytherin        1
## 6         Vincent Crabbe      Evil  Slytherin        1

Next, the following graph is just eye candy. It is a fun way to replicate the above graph in a more interactive way. The graph gives you the possibility to move the nodes around and with the filter on the left, select particular nodes (characters) and their closest relationships with other nodes.

(The graph is interactive, meaning you can alo zoom in/out but also can click on specific nodes and move them around. Plus, if the graph does not show in the Markdown, make sure it is in the same zip folder that the R document)

#Sets node information based on actors as well as their associated community

nodes <- data.frame(id = V(g11)$name, title = V(g11)$name, group = V(g11)$community)
nodes <- nodes[order(nodes$id, decreasing = F),]
edges <- get.data.frame(g11, what="edges")[1:2]

graphh<-visNetwork(nodes, edges) %>%
  visOptions(highlightNearest = TRUE, nodesIdSelection = TRUE) %>%
  visLegend(position = "right", main = "Group") 

visPhysics(graphh, stabilization = FALSE, adaptiveTimestep = FALSE, timestep = FALSE)

Network Visualization

As for the network visualization part, this will be explored both in Gephi and in Netlogo.

Conclusion

In conclusion, our analysis confirms Harry Potter as the most important character in the network. However, depending on your objective, it might be better to choose other characters that may have higher levels of degree or better diffusion capabilities. For example: Hermione seems to have the most influence on the whole network.

In all, if you need to pick a character to play in the future Harry Potter game, choose a character that belongs to the Gryffindor house and is aligned as a Good character. The chances of success may be greater, as most metrics identify these categories of characters as the most “connected”.